I need an External Rule to recursively change select part colors in an assembly

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The Inventor API is incredible, but its flexibility also makes it difficult for me to learn. After hours of working on this problem, I am crying for HELP! 🙂
I need an External Rule to recursively change select part colors in an assembly.
I have large assemblies with numerous sub-assemblies, three or four levels deep. The parts in the various assemblies are various colors and I want to be able to change those various colors (on the part level) with an external rule based on the individual part's starting color.
For instance, I may want to change the red parts to blue, but the green ones to yellow.
That means I need code that drills down to each part in each assembly, then assigns a new part color based on that part's current color.
This borrowed code more or less does what I want to do, but with the Material property instead of color:
Public Sub ChangeAllPartMaterial() ' Get the active assembly document. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Get the material to assign to all of the parts. Dim strMaterialName As String Dim oMaterial As Material On Error Resume Next oMaterial = oAsmDoc.Materials.Item(strMaterialName) On Error Goto 0 ' Iterate through all of the documents refrenced by the assembly. Dim oDoc As Document For Each oDoc In oAsmDoc.AllReferencedDocuments ' Check to see if this is a part. If oDoc.DocumentType = kPartDocumentObject Then Dim oPartDoc As PartDocument oPartDoc = oDoc ' Set the material.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''' Here I would like to assign the color, instead of the material ''''
''''' The new color would be based on what the old color was. ''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
strMaterialName = "Gold" oPartDoc.ComponentDefinition.Material = oMaterial End If Next End Sub
Any help would be greatly appreciated!
- Ron