Acad object survey


Sub demo_solid()
Call connect_acad
Dim objent As Acad3DSolid
Dim R As Double
R = 5

Call convert_pt0(R, 0, 0)
Set objent = acadDoc.ModelSpace.AddBox(pt0, 2, 1.5, 1)

Call convert_pt0(R, 45, 1)
Set objent = acadDoc.ModelSpace.AddCone(pt0, 1, 2)

Call convert_pt0(R, 90, 2)
Set objent = acadDoc.ModelSpace.AddCylinder(pt0, 1, 1)

Call convert_pt0(R, 135, 3)
Set objent = acadDoc.ModelSpace.AddSphere(pt0, 1)

Call convert_pt0(R, 180, 2)
Set objent = acadDoc.ModelSpace.AddTorus(pt0, 1.5, 0.375)

Call convert_pt0(R, 225, 1)
Set objent = acadDoc.ModelSpace.AddWedge(pt0, 2, 1, 1)

Call convert_pt0(R, 270, 0)
Set objent = acadDoc.ModelSpace.AddEllipticalCone(pt0, 2, 1, 2)

Call convert_pt0(R, 315, 1)
Set objent = acadDoc.ModelSpace.AddEllipticalCylinder(pt0, 1.5, 1, 1)

acadDoc.SendCommand "_shade" & vbCr
End Sub

Sub convert_pt0(R As Double, A As Double, Z As Double)
Dim A_rad As Double
Dim X As Double, Y As Double
A_rad = deg2rad(A)
X = R * Cos(A_rad)
Y = R * Sin(A_rad)
pt0(0) = X: pt0(1) = Y: pt0(2) = Z
End Sub

These are autocad primitive solids. There are interface commands to join them and cut.

There are also 3 vba methods to create solids from Region objects. A Region is a 2d figure, a bounded loop. It can be constructed from lines, polylines, circles, arcs, splines.

main page

dont forget to choose developer or search is stupid

To use these in a program we will need to develop Region techniques.

Sub revolve_code()
 'this is pseudo code, declarations are skipped, taken from autocad help file
 'to create a region, create an array of acad objects that form a coplanar loop
    Dim curves(0 To 1) As AcadEntity
 'addregion returns an array of regions, acadregion is not used as object type
    Dim regionObj As Variant
    Dim solidObj As Acad3DSolid
 'draw the loop objects and add them to the array
    Set curves(0) = acadDoc.ModelSpace.AddArc(centerPoint, radius, startAngle, endAngle)
    Set curves(1) = acadDoc.ModelSpace.AddLine(curves(0).StartPoint, curves(0).EndPoint)
 'addregion takes an array of acad objects
 'it will make multiple regions if fed appropriate data
 'return type is an array of region objects
    regionObj = acadDoc.ModelSpace.AddRegion(curves)
    Set solidObj = acadDoc.ModelSpace.AddRevolvedSolid(regionObj(0), axisPt, axisDir, angle)
End Sub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s