Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Using iLogic rule to change linework colors in a drawing file

sam_dobell
Participant

Using iLogic rule to change linework colors in a drawing file

sam_dobell
Participant
Participant

Hi, 

 

I am trying to create a rule that will take any selected linework of an assembly or part file (Edge Priority & Part Priority) in an idw file and change the color of the linework to a specific color. 

 

I currenty have this code which will run, but does not change the color. It doesn't produce any errors so I'm having some trouble diagnosing the issue. 

 

' Get the active document
Dim doc As Document = ThisApplication.ActiveDocument

' Check if the document is a drawing
If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
    Dim drawingDoc As DrawingDocument = doc

    ' Get the selected objects
    Dim selectedObjects As SelectSet = ThisApplication.ActiveDocument.SelectSet

    ' Define the new color
    Dim newColor As Color = ThisApplication.TransientObjects.CreateColor(0, 162, 222)

    ' Loop through the selected objects and change their color
    For Each obj In selectedObjects
        If TypeOf obj Is DrawingCurve Then
            Dim curve As DrawingCurve = obj
            ' Change the color of each segment in the curve
            For Each segment As DrawingCurveSegment In curve.Segments
                segment.OverrideColor = newColor
            Next
        End If
    Next
Else
    MessageBox.Show("Please open a drawing document.")
End If

 Thanks in advance!

0 Likes
Reply
33 Views
1 Reply
Reply (1)

Michael.Navara
Advisor
Advisor

What you get from SelectSet is not DrawingCurve but DrawingCurveSegment. Also OverrideColor is not a member of DrawingCurveSegment. You can change the color of the entire DrawingCurve.

Try this modified code

 

 

' Get the active document
Dim doc As Document = ThisApplication.ActiveDocument

' Check if the document is a drawing
If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
    Dim drawingDoc As DrawingDocument = doc

    ' Get the selected objects
    Dim selectedObjects As SelectSet = ThisApplication.ActiveDocument.SelectSet

    ' Define the new color
    Dim newColor As Color = ThisApplication.TransientObjects.CreateColor(0, 162, 222)

    ' Loop through the selected objects and change their color
    For Each obj In selectedObjects
        If TypeOf obj Is DrawingCurveSegment Then
            Dim curve As DrawingCurve = obj.Parent
			curve.Color = newColor
'            ' Change the color of each segment in the curve
'            For Each segment As DrawingCurveSegment In curve.Segments
'                segment.OverrideColor = newColor
'            Next
        End If
    Next
Else
    MessageBox.Show("Please open a drawing document.")
End If

 

 

0 Likes