Add "Chrome" effect to a part using AutoDesk Inventor VBA

Add "Chrome" effect to a part using AutoDesk Inventor VBA

isocam
Collaborator Collaborator
398 Views
1 Reply
Message 1 of 2

Add "Chrome" effect to a part using AutoDesk Inventor VBA

isocam
Collaborator
Collaborator

Can anybody help?

Does anybody know how I can add a "Chrome Plated" effect to a AutoDesk Inventor part (ipt) using a VBA macro?

Many thanks in advance!!!!

Darren

0 Likes
399 Views
1 Reply
Reply (1)
Message 2 of 2

chandra.shekar.g
Autodesk Support
Autodesk Support

@isocam,

 

Try below VBA code to change effect.

 

Sub ChromePlated_Appearance()    
    
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' Get an appearance from the document.  To assign an appearance is must
    ' exist in the document.  This looks for a local appearance and if that
    ' fails it copies the appearance from a library to the document.
    Dim localAsset As Asset
    On Error Resume Next
    Set localAsset = oDoc.Assets.Item("Chrome - Polished")
    If Err Then
        On Error GoTo 0
        
        ' Failed to get the appearance in the document, so import it.
        
        ' Get an asset library by name.  Either the displayed name (which
        ' can changed based on the current language) or the internal name
        ' (which is always the same) can be used.
        Dim assetLib As AssetLibrary
        Set assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
        'Set assetLib = ThisApplication.AssetLibraries.Item("314DE259-5443-4621-BFBD-1730C6CC9AE9")
        
        ' Get an asset in the library.  Again, either the displayed name or the internal
        ' name can be used.
        Dim libAsset As Asset
        Set libAsset = assetLib.AppearanceAssets.Item("Chrome - Polished")
        
        ' Copy the asset locally.
        Set localAsset = libAsset.CopyTo(oDoc)
    End If
    
    oDoc.ActiveAppearance = localAsset
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network