AutoCAD VBA - simple code to draw line with colour information

Submitted by timed on Sat, 11/24/2018 - 10:20
autocad vba draw lines with coulurs

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

 

 

FULL CODE

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
LinObj.Update

Case 2
LinObj.color = acCyan
LinObj.Update

Case 3
LinObj.color = acGreen
LinObj.Update

Case 4
LinObj.color = acRed
LinObj.Update

Case 5
LinObj.color = acYellow
LinObj.Update

Case 6
LinObj.color = acBlue
LinObj.Update

Case 7
LinObj.color = acMagenta
LinObj.Update

Case Else
'LinObj.color = acWhite
LinObj.Update
End Select

'computeraidedautomation.com

End Function

autocad vba

 

Tags