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: 

I want to change the whole assembly parts appearance using vba

1 REPLY 1
SOLVED
Reply
Message 1 of 2
k14348
454 Views, 1 Reply

I want to change the whole assembly parts appearance using vba

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.

 

1 REPLY 1
Message 2 of 2
Sergio.D.Suárez
in reply to: k14348

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


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

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report