Hi Sergio,
I have one main assembly, In that i have 4 sub assemblies and Main Parts. Sub assemblies also have some parts.
Now i would like to change part appearance for each part. I have a code which you have given for one part.
Public Sub SetYellowPartColor() Dim oPartDoc As PartDocument Set oPartDoc = ThisApplication.ActiveDocument ' Get a reference to the RenderStyle named "Red". Dim oRenderStyle As RenderStyle Set oRenderStyle = oPartDoc.RenderStyles.Item("Yellow") ' Assign the render style to the part. oPartDoc.ActiveRenderStyle = oRenderStyle ' Force the view to update to see the change. ThisApplication.ActiveView.Update End Sub
Now i would like to do this for each components in assembly.
Could you please help me on this.
Solved! Go to Solution.
Solved by Sergio.D.Suárez. Go to Solution.
Sorry for taking a long time to answer, I think that for an assembly the same code could be applied as shown below.
Sub Change_All_PartColor() Dim oAsmDoc As AssemblyDocument Set oAsmDoc = ThisApplication.ActiveDocument ' Get the assembly component definition. Dim oAsmDef As AssemblyComponentDefinition Set oAsmDef = oAsmDoc.ComponentDefinition ' Get all of the leaf occurrences of the assembly. Dim oLeafOccs As ComponentOccurrencesEnumerator Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences ' Iterate through the occurrences and print the name. Dim oOcc As ComponentOccurrence For Each oOcc In oLeafOccs On Error Resume Next Dim oDoc As Document Set oDoc = oOcc.Definition.Document ' Get a reference to the RenderStyle named "Yellow". Dim oRenderStyle As RenderStyle Set oRenderStyle = oDoc.RenderStyles.Item("Yellow") ' Assign the render style to the part. oDoc.ActiveRenderStyle = oRenderStyle ' Force the view to update to see the change. ThisApplication.ActiveView.Update Next End Sub
I hope it will help you solve your problem. regards
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Can't find what you're looking for? Ask the community or share your knowledge.