Introduction: Create AutoCAD User Form

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

Step 1: Video and VBA Codes

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

Comments

author
Mohsen Falat made it! (author)2017-03-15

Hi
I start VBA IDE in AutoCAD 2017(2014) x64

when try to create new UserFrom VBA report this error msg :

Class not registered

Looking for object with

CLSID:{C62A69F0-16DC-11CE-9E98-00AA00574A4F}

i dont know why ! and how can i fix this ?!

Untitled - 1.jpg
author
DIY Hacks and How Tos (author)2016-06-26

Great tutorial. Thanks for sharing.

About This Instructable

326views

10favorites

License:

Bio: Interested in Computer aided automation things
More by computeraidedautomation:Create AutoCAD user form
Add instructable to: