Hi Friends, in this article I will explain about how to drawa line using VBA.
I already explained in the previous article,Introduction to VBA and what are VBA and how to open Visual Basic Editor
First open the AutoCAD application—Tools – Visual Basic
Editor.
Take one user Form ,
Previous article i explained about how to open userform,run the form.
Drag and Drop the one commandbutton
,write or simply copy and paste the below code.
Private
Sub CommandButton1_Click()
Call
Drawline
Unload
Me
End
Sub
Public
Sub Drawline()
Dim line As AcadLine
Dim StartPoint(0 To 2) As Double
Dim EndPoint(0 To 2) As Double
'Define startpoint the line point
StartPoint(0) = 0: StartPoint(1) = 20:
StartPoint(2) = 30
'Define endpoint the line point
EndPoint(0) = 100: EndPoint(1) = 100:
EndPoint(2) = 30
'Create a line in model space
Set line =
ThisDrawing.ModelSpace.AddLine(StartPoint, EndPoint)
End Sub
|
AddLine method must need the 2 parameters, StartPoint and EndPoint.
In AutoCAD point has the
list of 3 values X-coordinate Y-coordinate and Z-coordinate.Thats why i took
the StartPoint (0 To 2),StartPoint and EndPoint are a list of 3 values.
In the above example we write
the Drawline()
sub procedure and call this
procedure in the commandButton click function as Call
Drawline.
UnLoad
Me closes the window and open the Visual
Basic Editor.
When we execute the above code
then it draw the line in the autocad between the points (0,20,30) and (100,100,30).
Happy Reading My Blog Autolisp-roja .If you like my blog then please share my blog with your friends.
I like your sharing.
ReplyDeleteThanks you.
Welcome.....I want all your supports then i will write more useful articles....
Deletemuch more simpler autocad vba code for line drawing
Delete