I think you need to check the color red, green and blue values for a good comparison. check the function "IsSameColor" in the iLogic rule below. Also if the color was never set before then the property "OverrideColor" will return "Nothing" you need to check for that.
I also discovered that you need to cast the sketch entity to the real entity type to be able to update the color. check the function "SetColorToSketchEntity"
Last thing to note I used iLogic instead of VBa. This is because I think VBa is obsolete and you should not use it anymore if possible. (Check my blog post on that topic!)
Sub Main()
Dim oSketch As PlanarSketch = ThisApplication.ActiveEditObject
Dim oColorRed As Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
Dim oColorGreen As Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
For Each oSketchEntity As SketchEntity In oSketch.SketchEntities
If TypeOf oSketchEntity Is SketchPoint Then Continue For
If oSketchEntity.OverrideColor Is Nothing Then
' SketchEntity color was never set. Set it to red as initial value
SetColorToSketchEntity(oSketchEntity, oColorRed)
Else
Dim color As Color = oSketchEntity.OverrideColor
If IsSameColor(color, oColorRed) Then
SetColorToSketchEntity(oSketchEntity, oColorGreen)
End If
End If
Next
End Sub
Public Function IsSameColor(color1 As Color, color2 As Color) As Boolean
Return (color1.Red = color2.Red AndAlso color1.Green = color2.Green AndAlso color1.Blue = color2.Blue)
End Function
Public Sub SetColorToSketchEntity(sketchEntity As SketchEntity, color As Color)
Select Case sketchEntity.Type
Case ObjectTypeEnum.kSketchLineObject
Dim se As SketchLine = sketchEntity
se.OverrideColor = color
Case ObjectTypeEnum.kSketchCircleObject
Dim se As SketchCircle = sketchEntity
se.OverrideColor = color
Case ObjectTypeEnum.kSketchArcObject
Dim se As SketchArc = sketchEntity
se.OverrideColor = color
Case Else
' this example does not include all types:
' SketchArc, SketchCircle, SketchControlPointSpline, SketchEllipse,
' SketchEllipticalArc, SketchEquationCurve, SketchFixedSpline,
' SketchLine, SketchOffsetSpline, SketchPoint, SketchSpline
MsgBox("Unable to set color of sketch Entity of type: " & sketchEntity.Type)
End Select
End Sub
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com