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: 

Change part's color override VBA code

1 REPLY 1
Reply
Message 1 of 2
Anonymous
1363 Views, 1 Reply

Change part's color override VBA code

How can i change a part's color override through VBA code?

1 REPLY 1
Message 2 of 2
ruthsteed
in reply to: Anonymous

That depends on what you mean.  Do you mean you want to change the part color in the part itself or in the context of an assembly?  This sub will set the part color if the active document is a part, or the first occurrence's color if the active document is an assembly. It assumes that the "Gold" color style is not already in your document.

 

Sub PartColor()
    Dim oAsset As Asset
    Dim oLib As AssetLibrary: Set oLib = ThisApplication.AssetLibraries("Autodesk Appearance Library")
    Set oAsset = oLib.AppearanceAssets("Gold")
    If ThisApplication.ActiveDocumentType = kPartDocumentObject Then
        Dim oPart As PartDocument: Set oPart = ThisApplication.ActiveDocument
        oPart.ActiveAppearance = oAsset
    ElseIf ThisApplication.ActiveDocumentType = kAssemblyDocumentObject Then
        Dim oAsm As AssemblyDocument: Set oAsm = ThisApplication.ActiveDocument
        Set oAsset = oAsset.CopyTo(oAsm)
        Dim oOcc As ComponentOccurrence
        Set oOcc = oAsm.ComponentDefinition.Occurrences(1)
        oOcc.Appearance = oAsset
    End If
End Sub

 



Ruth Steed
Inventor Development Team
Autodesk, Inc.

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

Post to forums  

Autodesk Design & Make Report