iLogic to change Part Appearance

iLogic to change Part Appearance

J_Dumont
Advocate Advocate
3,756 Views
9 Replies
Message 1 of 10

iLogic to change Part Appearance

J_Dumont
Advocate
Advocate

Hello. I am hoping someone can help me with iLogic code to change the appearance of a part at the part level. I want to make the change in the part itself and not just override the color at the assembly level.

Any help would be greatly appreciated.

 

0 Likes
Accepted solutions (1)
3,757 Views
9 Replies
Replies (9)
Message 2 of 10

bradeneuropeArthur
Mentor
Mentor

Hi,

 

From what do you want to change into?

For example "red" into "blue"?

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 10

J_Dumont
Advocate
Advocate

Hello, thanks for the quick response.

From the assembly, I have a multi-value parameter with several choices, ie Red, White, Green, etc.

I have the necessary appearances in each part file that I would like to use and once the user decides which color each part is to be I would like to recursively go through the assembly and change each part appearance to match.

 

 

0 Likes
Message 4 of 10

Darkforce_the_ilogic_guy
Advisor
Advisor

how would you like to make it ?.... where is the multi-value parameter  stored ?

0 Likes
Message 5 of 10

J_Dumont
Advocate
Advocate

The multi-value parameter is defined in the assembly. The user would select the material and color for all components.

For example, the user selects material and then color, ie. Aluminum as material and White as color. I need the appearance to change at the part level for other uses.

I have the material working but I'm stuck on the appearance.

 

 

0 Likes
Message 6 of 10

Sergio.D.Suárez
Mentor
Mentor

Hi, the ilogic code that I write to you below is activated from an assembly. The code changes the color at the part level, not assembly, maybe the lines that are found after loading the current appearances to the selection list.
I hope that part of the code can be useful

 

Dim oAsset As Asset
Dim oAsset_Array As New ArrayList
For Each oAsset_Array_X In ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
oAsset_Array.Add(oAsset_Array_X.DisplayName)
oAsset_Array.Sort()
Next
'present the user with the list to choose from
oAsset_Array_Selected = InputListBox("CHOOSE TEXTURE FROM ABOVE LIST", oAsset_Array, oAsset_Array.Item(0), "TEXTURE SELECTION", "LIST OF TEXTURES")
If oAsset_Array_Selected = "" Then Exit Sub

Dim comps As ObjectCollection
Dim comp As Object
comps = ThisApplication.TransientObjects.CreateObjectCollection

While True
	comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a component") 
		
	' If nothing gets selected then we're done	
	If IsNothing(comp) Then Exit While
	comps.Add(comp) 
End While

' If there are selected components we can do something
For Each comp In comps
	Dim oDef As PartDocument
    oDef = comp.Definition.Document
    Dim oRenderStyle As RenderStyle
    oRenderStyle = oDef.RenderStyles.Item(oAsset_Array_Selected)
    oDef.ActiveRenderStyle = oRenderStyle
    iLogicVb.UpdateWhenDone = True		
Next

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 7 of 10

J_Dumont
Advocate
Advocate

Hi Sergio,

This looks great and it works perfectly when selecting components. 

Could I impose on you once more?

I would like to change all of the components to the material selected instead of prompting the user to select a component.

0 Likes
Message 8 of 10

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

I think you could try this code, I have not tried it, I hope it helps. regards

 

Dim oAsset As Asset
Dim oAsset_Array As New ArrayList
For Each oAsset_Array_X In ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
oAsset_Array.Add(oAsset_Array_X.DisplayName)
oAsset_Array.Sort()
Next
'present the user with the list to choose from
oAsset_Array_Selected = InputListBox("CHOOSE TEXTURE FROM ABOVE LIST", oAsset_Array, oAsset_Array.Item(0), "TEXTURE SELECTION", "LIST OF TEXTURES")
If oAsset_Array_Selected = "" Then Exit Sub


For Each oOcc As ComponentOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
	On Error Resume Next
	Dim oDef As PartDocument
    oDef = oOcc.Definition.Document
    Dim oRenderStyle As RenderStyle
    oRenderStyle = oDef.RenderStyles.Item(oAsset_Array_Selected)
    oDef.ActiveRenderStyle = oRenderStyle
    iLogicVb.UpdateWhenDone = True		
Next

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 9 of 10

J_Dumont
Advocate
Advocate

HI Sergio,

Your code works perfectly.

I was trying to make a small edit and hopefully, you can help me out as I'm unfamiliar with the ActiveRenderStyle syntax.

In my code, I have a multi-parameter list that the user chooses from a predefined list of colors so I do not need to create a list of appearances. See the attached image.

The problem I'm having is passing the text value to, 

oDef.ActiveRenderStyle = <String value of color choice>

Form image.jpg

Message 10 of 10

J_Dumont
Advocate
Advocate

Hi Sergio,

Please disregard. I was able to get my code working. I couldn't have done it without your help.

Thank you.

For Each oOcc As ComponentOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
	On Error Resume Next
	Dim oDef As PartDocument
    oDef = oOcc.Definition.Document
    Dim oRenderStyle As RenderStyle
    oRenderStyle = oDef.RenderStyles.Item(GrillColor) 
    oDef.ActiveRenderStyle = oRenderStyle
    iLogicVb.UpdateWhenDone = True		
Next