iLogic to change color of component of a sub-assembly

iLogic to change color of component of a sub-assembly

Anonymous
Not applicable
4,300 Views
8 Replies
Message 1 of 9

iLogic to change color of component of a sub-assembly

Anonymous
Not applicable

If the component is on the top level, I can use this to change its color:

 

Componment.Color("TopLevelPart:1") = "Red"

 

The same does not work when the part is in a sub-assembly.   How can I do the same for each part in an assembly?

 

I have tried,

 

Componment.Color("SubAssemblyPart:1") = "Red"

 

and

 

Componment.Color("TopLevelAssembly", "SubAssemblyPart:1") = "Red"

 

But neither changes the SubAssemblyPart.

 

iProperties.PartColor = "Red" works as a rule run in a part file, but not an assembly.

 

For an assembly, another option is to use a rule function:

 

iProperties.Value("filename.ipt", "property tab name", "property name")

 

But I can't figure out if "PartColor" is the correct "property name" or what the right value for "property tab name" is. 

 

Thanks!

 

 

4,301 Views
8 Replies
Replies (8)
Message 2 of 9

DRudaz
Enthusiast
Enthusiast

HI,

 

Maybe to late....

 

Use the command makepath like this :

 

Component.Color(MakePath("assembly:1","Part:1"))="RED"

 

Regards

 

Dominique

 

Salutations,
Dominique

Autodesk Certified Instructor - Gold / Inventor Certified Professional


0 Likes
Message 3 of 9

insomnix
Advocate
Advocate

I was running into the same problem. Found this post in the search to resolve my issue and thought I would come back with the solution I found through some trial and error.

 

In the code below I am iterating through sub assemblies to set the color of parts and it is designed to drill down into the sub assembly. I was trying to use "Component.Color" to change the color of sub parts and ran into a similar problem. Strangely, the part would have the new color associated with it when I examine the part, but it would not update the color on the screen.

 

When I changed the code to use "SetRenderStyle" the color would update correctly. Hope this helps the next person that comes along with this issue.

 

 

Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument

' set color for the standard screws
Call SetColor(asmDoc.ComponentDefinition.Occurrences,"R14400","Zinc")SyntaxEditor Code Snippet
Private Sub SetColor(Occurrences As ComponentOccurrences, SearchName As String, Color As String)
    ' Iterate through each of the occurrences in the collection provided.
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 
    Dim occ As ComponentOccurrence
    For Each occ In Occurrences
        ' Check to see if the object is active.
        If Component.IsActive(occ.Name) = True Then            
        ' Check to see if the part number from the iProperties matches the search name.
            If iProperties.Value(occ.Name, "Project", "Part Number") = SearchName Then
                ' Set the part color
                'Component.Color(occ.Name) = Color
                Call occ.SetRenderStyle(kOverrideRenderStyle,oAsmDoc.RenderStyles.Item(Color))
            End If
        
            If occ.DefinitionDocumentType = kAssemblyDocumentObject Then
                If Component.IsActive(occ.Name) = True Then
                    Call SetColor(occ.SubOccurrences, SearchName, Color)
                End If
            End If
        End If
    Next
End Sub

 

0 Likes
Message 4 of 9

dusan.naus.trz
Advisor
Advisor

Hi,

I tried your code in version Inventor 2020 and doesn't work.

0 Likes
Message 5 of 9

insomnix
Advocate
Advocate

I don't have 2020, so no way for me to test, but I would think it would still work. Did you change any of the code? Did you place the first snippet of code into the Main sub?

0 Likes
Message 6 of 9

dusan.naus.trz
Advisor
Advisor

Hi,
I'm sorry. I'm getting started with iLogic and I don't understand much yet. But I'm learning. Error see video. I have version Inventor 2019 and 2020. Please can you help? Thank you.

0 Likes
Message 7 of 9

insomnix
Advocate
Advocate

The second snippet of code is a procedure. Whenever you use functions or procedures in iLogic, a primary procedure must be created called Main. Any code you would normally place directly into the rule would be placed inside the Main procedure. Replace the first snippet of code with below.

 

Also, make sure you replace "R14400" with the name of the part you want to change color.

 

Sub Main()
Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument

' set color for the standard screws
Call SetColor(asmDoc.ComponentDefinition.Occurrences,"R14400","Zinc")SyntaxEditor Code Snippet
End Sub
Message 8 of 9

dusan.naus.trz
Advisor
Advisor
Thank you. Great.
I gave this as a comment (SyntaxEditor Code Snippet) Then everything works without error.
0 Likes
Message 9 of 9

KarlH_
Participant
Participant

Wondering if anyone has found a different/easier method of executing the below Part Colour commands from an assembly without having to host the code within the part itself;

 

iProperties.PartColor = Part_Colour
iLogicVb.UpdateWhenDone = True

Logger.Info(ThisDoc.FileName.ToString + ", " + iLogicVb.RuleName.ToString + ", " + Part_Colour)

 

I've tried a few methods of changing the part colour from an assembly, but all have proven messy due to multiple View Reps (in both part and assembly) with unwanted colour overrides messing things up. 

 

The "iProperties.PartColor" command does exactly what I need when executed in the Part whilst the Master View Rep (as all other Part View Reps then match the master) is active - however it's annoying knowing that I'm nesting this code within the part, when really I'm needing it executed from the assembly upon the part(s).

 

Appreciate anyone's help on this!

 

As a side note, I've solved this problem with iLogic external rules but unfortunately can't use them in the dev environment due to reasons.

0 Likes