17, Feb, 2019

AutoCAD VBA 3D Extrude Example 6. (user form project)

autocad

Use VBA USer form to create 3D extrsion in Autocad

Refer previous articles (to create userform project)

VBA Code  (Reference : AutoCAD 2004 VBA: A Programmer’s Reference, By Joe Sutphin)

Private Sub CommandButton1_Click()
Me.Hide
Dim varCenter(0 To 2) As Double
Dim dblRadius As Double
Dim dblHeight As Double
Dim dblTaper As Double
Dim strInput As String
Dim varRegions As Variant
Dim objEnts() As AcadEntity
Dim objEnt As Acad3DSolid
Dim varItem As Variant
Dim rad As Integer
Dim height As Integer
On Error Resume Next
”values from text boxes
rad = TextBox1.Text
height = TextBox2.Text
” define center point
varCenter(0) = 0: varCenter(1) = 0: varCenter(2) = 0
” draw the entities
With ThisDrawing.ModelSpace
” draw the outer region (circle)
ReDim objEnts(0)
Set objEnts(0) = .AddCircle(varCenter, rad) ‘ radius
” create the region
varRegions = .AddRegion(objEnts)
” extrude the solid
Set objEnt = .AddExtrudedSolid(varRegions(0), height, 0) ’10 extrude height and 0 taper angle
” update the extruded solid
objEnt.Update
End With

If Err Then MsgBox Err.Description
” delete the temporary geometry
For Each varItem In objEnts
varItem.Delete
Next
For Each varItem In varRegions
varItem.Delete
Next
ThisDrawing.SendCommand “_shade” & vbCr
End Sub

Paste above code

AutoCAD VBA 3D Extrude

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>