Using iLogic rule to change linework colors in a drawing file

Using iLogic rule to change linework colors in a drawing file

sam_dobell
Participant Participant
258 Views
3 Replies
Message 1 of 4

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
259 Views
3 Replies
Replies (3)
Message 2 of 4

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
Message 3 of 4

sam_dobell
Participant
Participant

Thanks so much, this works perfectly when the selection is set to Edge Priority.

Is it possible to make it work with both Edge Priority & Part Priority? (so entire part lineworks can be changed)

0 Likes
Message 4 of 4

Michael.Navara
Advisor
Advisor

This is not possible directly. Because when you look at the SelectSet content when you have selected component with PartPriority, you find a GenericObject.

 

But if you want to invest some effort, the similar functionality can be achieved. You need to combine SelectEvents and DrawingView.DrawingCurves property.

You set selection filter to kDrawingCurveSegmentFilter and from the drawing curve segment you can obtain model geometry and containing occurrence.

This occurrence you can pass to the DrawingCurves property as an argument and you obtain all drawing curves related to it.

This can be done in both OnSelect and OnPreSelect events and the look can be similar to PartPriority selection.

 

This is hard to achieve in iLogic, it is much better to create your own add-in with this functionality. The code is too complex for this forum. I can give you some hints, but I'm not able to do it completely.

 

0 Likes