Computer Aided Automation
AutoCAD VBA - Draw line in different colour - Printable Version

+- Computer Aided Automation (https://computeraidedautomation.com)
+-- Forum: CAA Discussions (https://computeraidedautomation.com/forum-7.html)
+--- Forum: VBA Programming (https://computeraidedautomation.com/forum-1.html)
+---- Forum: AutoCAD VBA (https://computeraidedautomation.com/forum-3.html)
+---- Thread: AutoCAD VBA - Draw line in different colour (/thread-7.html)



AutoCAD VBA - Draw line in different colour - techberth - 21-11-2019

change the variable c (below code) to change the colour of line object

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

End Function