21, Feb, 2019

AutoCAD VBA – simple code to draw line with colour information

autocad vba draw line

Simple Code to Draw lines in AutoCAD VBA

‘call statement

Call drawline(x1, y1, x2, y2, 1)

replace x1, y1, x2, y2 with your X and Y cordinates

replace 1 with colour of choice

available colours

1 : White

2 : Cyan

3 : Green

4 : Red

5 : Yellow

6 : Blue

7 : Magenta


Function drawline(ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double, ByVal c As Integer)
Dim Startpoint(0 To 2) As Double
Dim Endpoint(0 To 2) As Double
Dim LinObj As AcadLine
  ‘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
 ‘Line object in to drawing space

Set LinObj = ThisDrawing.ModelSpace.AddLine(Startpoint(), Endpoint())

Select Case c

Case 1
LinObj.color = acWhite

Case 2
LinObj.color = acCyan

Case 3
LinObj.color = acGreen

Case 4
LinObj.color = acRed

Case 5
LinObj.color = acYellow

Case 6
LinObj.color = acBlue

Case 7
LinObj.color = acMagenta

Case Else
‘LinObj.color = acWhite
End Select


End Function

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>