21 | 08 | 2017

Create Line

We are going to start by creating a little piece of code to create a simple line object. Open the editor with ALT & F11 and create the following text in the thisdrawing object.
You could see this code as a alternative LINE command. You follow the same steps as when you do this manually. You first provide the start coordinates then the end coordinates and finally you order VBA to place the line between those two tutorials

Code:

Sub CreatelineObject()

'****************************************
'*** Code from VisibleVisual.com ********
'****************************************
 
Dim Startpoint(0 To 2) As Double
Dim Endpoint(0 To 2) As Double
 
'Start Coordinates Coordinates XYZ
Startpoint(0) = 0: Startpoint(1) = 0: Startpoint(2) = 0
 
'End Coordinates Coordinates XYZ
Endpoint(0) = 100: Endpoint(1) = 100: Endpoint(2) = 0
 
ThisDrawing.ModelSpace.AddLine Startpoint(), Endpoint()
 
ZoomAll
End Sub

Now add more coordinates and create the following drawing.

See the result below:

Code:

Sub CreateHouse()

CreatelineObject 0, 100, 0, 0
CreatelineObject 0, 0, 100, 0
CreatelineObject 100, 0, 0, 100
CreatelineObject 0, 100, 50, 150
CreatelineObject 50, 150, 100, 100
CreatelineObject 100, 100, 100, 0
CreatelineObject 100, 0, 100, 100
CreatelineObject 100, 100, 0, 0
 
ZoomAll
End Sub
 
 
Function CreatelineObject(x1, y1, x2, y2)
'****************************************
'*** Code from VisibleVisual.com ********
'****************************************
Dim Startpoint(0 To 2) As Double
Dim Endpoint(0 To 2) As Double
 
'Start Coordinates Coordinates XYZ
Startpoint(0) = x1: Startpoint(1) = y1: Startpoint(2) = 0
 
'End Coordinates Coordinates XYZ
Endpoint(0) = x2: Endpoint(1) = y2: Endpoint(2) = 0
 
 
ThisDrawing.ModelSpace.AddLine Startpoint(), Endpoint()
 
End Function

As you can imagine this is a rather complicated code to create this object. A Polyline can be created with less code then this. See the PolyLine tutorial how to simplify the code.

Download AutoCad sample Here

 

Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2330644
Latest Articles