Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AutoCAD VBA - Draw line in different colour
#1
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
Reply
#1
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
Reply
CAA


Forum Jump:


Users browsing this thread: 1 Guest(s)