Create AutoCAD User Form

by computeraidedautomation in Circuits > Computers

3279 Views, 10 Favorites, 0 Comments

Create AutoCAD User Form

11.jpg

How to create a user form for AutoCAD (VBA) to create a circle by entering the values like Radius, X & Y Coordinates of Center Point.

If you are a beginner, please refer our previous videos/tutorials (available at our web portal, computeraidedautomation.com) to have an idea about AutoCAD VBA programming
Step by Step Procedure is shown below

Step 1 : Create a New Macro from VBA Manager

Step 2 : Open Code editor (Visual Basic Editor)

Step 3 : Insert User Form , Labels, Text Boxes and Button (see the video)

Step 4 : Double click on Command Button and paste codes given at the bottom of this post

Step 4 : Save the Macro

Step 5 : Run the Macro

Step 6 : Input the Values for Radius and Center X, Y

Save the Drawing

Video and VBA Codes

AutoCAD VBA User Form : Create Circle

download full code at

'www.computeraidedautomation.com

Private Sub CommandButton1_Click()
Me.hide ‘hide the editor while running the macro

Dim R As Variant

Dim X As Variant

Dim Y As Variant

Dim Center(0 To 2) As Double

Dim objEnt As AcadCircle

On Error Resume Next ‘bypass run time errors

With ThisDrawing.Utility

R = TextBox1.Text

X = TextBox2.Text

Y = TextBox3.Text

Center(0) = X: Center(1) = Y: Center(2) = 0

End With

‘ draw the circle

If ThisDrawing.ActiveSpace = acModelSpace Then

Set objEnt = ThisDrawing.ModelSpace.AddCircle(Center, R)

Else

Set objEnt = ThisDrawing.PaperSpace.AddCircle(Center, R)

End If

objEnt.Update

End Sub