Autodesk Inventor 2022 VBA - Set Part Chrome or Set Part Colour

Autodesk Inventor 2022 VBA - Set Part Chrome or Set Part Colour

isocam
Collaborator Collaborator
326 Views
2 Replies
Message 1 of 3

Autodesk Inventor 2022 VBA - Set Part Chrome or Set Part Colour

isocam
Collaborator
Collaborator

Can anybody help?

 

Please see the two attached macro files.

 

Can anybody create a simple extruded part and test each macro?

 

The first should change the part colour to chrome. My graphics card is not suitable to show chromed parts properly.

 

Does it actually change the part to a chromed finish???

 

Secondly, Please try the second macro to change the part colour to RGB

 

I cannot get this one to work, I am using Inventor 2022. Does anybody know what is wrong with the macro?

 

Many thanks in advance!!

 

Darren

0 Likes
327 Views
2 Replies
Replies (2)
Message 2 of 3

Ed__Jobe
Mentor
Mentor

Some of your logic is not good programming practice. This topic has a solution. But it is in iLogic. It's very similar to VBA though.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 3

Ed__Jobe
Mentor
Mentor

Here's a tested vba version for setting chrome.


Public Function SetPartChrome()

    Dim oPDoc As PartDocument
    Set oPDoc = ThisDocument
    Dim localAsset As Asset
    Dim assetLib As AssetLibrary
    Dim libAsset As Asset
    
    
    On Error Resume Next
    Set localAsset = oPDoc.MaterialAssets.Item("Chrome - Polished")
    If Err Then
        On Error GoTo 0

        Set assetLib = ThisApplication.AssetLibraries.Item("Autodesk Material Library")
        Set libAsset = assetLib.AppearanceAssets.Item("Chrome - Polished")
        Set localAsset = libAsset.CopyTo(oPDoc)
    End If
    
    ThisDocument.ActiveMaterial = localAsset
    
    'When you change the material to chrome,
    'the appearance is automatically set to Default.
    'Uncomment the section below if you also want to override to chrome.
    
'    On Error Resume Next
'    Set localAsset = oPDoc.Assets.Item("Chrome - Polished")
'    If Err Then
'        On Error GoTo 0
'
'        Set assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
'        Set libAsset = assetLib.AppearanceAssets.Item("Chrome - Polished")
'        Set localAsset = libAsset.CopyTo(oPDoc)
'    End If
'
'    ThisDocument.ActiveAppearance = localAsset
    
End Function

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes