Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change the parts color

1 REPLY 1
Reply
Message 1 of 2
m_nasirshoaibi
211 Views, 1 Reply

Change the parts color

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.

1 REPLY 1
Message 2 of 2
A.Acheson
in reply to: m_nasirshoaibi

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? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report