Hi Everyone,
I've created an assembly comprising of two parts.
In each part, I've written a rule called "Change the Parts Color". This code dynamically alters the color of the part based on its thickness.
If Thickness = 1 Then
Feature.Color("Extrusion1") = "Red"
Else If Thickness = 2 Then
Feature.Color("Extrusion1") = "Green"
End If
Additionally, I've written a rule named "Change the Colors" within the assembly state.
' Enable automatic updates when changes are made
iLogicVb.UpdateWhenDone = True
' Get the active assembly document
Dim oAsm As AssemblyDocument = ThisDoc.Document
' Loop through all referenced documents in the assembly
For Each oRefDoc As Document In oAsm.AllReferencedDocuments
' Check if the referenced document is a part or assembly and if it has occurrences in the assembly
If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Or oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject AndAlso _
oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
On Error Resume Next 'Temporarily suppresses error messages to continue execution even if the specified rule does not exist.
iLogicVb.Automation.RunRule(oRefDoc, "Change the Parts Color") ' Runs the "Rule0" iLogic rule in the referenced document.
End If
Next
Upon executing the "Change the Colors" rule in the assembly, it automatically triggers the "Change the Parts Color" rule within each part, resulting in a comprehensive color change across the entire assembly.
To make things even better, I think it would be a good idea to include the "Change the Parts Color" rule inside the "Change the Colors" rule. Which would be easier and more efficient. For instance, if we have more parts, it could be time consuming to add "Change the Parts Color," for each part.
Does anyone have an idea?
Thank you all in advance.
My preference would be to keep a rule like this as external rule unless their is some interaction within the part itself via a form or very specific internal rules. When using an external rule you will just need some iproperty or document specific item that will identify the part to target. Are these sheetmetal parts by any chance?
Can't find what you're looking for? Ask the community or share your knowledge.