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 Material of part in assembly - Inventor 2014 / 2015

5 REPLIES 5
Reply
Message 1 of 6
GeorgK
782 Views, 5 Replies

Change Material of part in assembly - Inventor 2014 / 2015

Hello together,

 

how could I change the material of a part in an assembly? I would like to select the part and change the material.

 

This works in part-environment:

http://adndevblog.typepad.com/manufacturing/2013/07/inventor-2014-api-set-part-material.html

 

Thanks Georg

5 REPLIES 5
Message 2 of 6
philippe.leefsma
in reply to: GeorgK

Hi Georg,

 

Here is a sample that sets an occurrence appearrance:

 

Public Sub SetOccurrenceAppearance()

    Dim asmDoc As AssemblyDocument
    Set asmDoc = 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 = asmDoc.Assets.item("Bamboo")
   
    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("Bamboo")
        'Set libAsset = assetLib.AppearanceAssets.Item("ACADGen-082")
       
        ' Copy the asset locally.
        Set localAsset = libAsset.CopyTo(asmDoc)
    End If
    On Error GoTo 0
          
    ' Have an occurrence selected.
    Dim occ As ComponentOccurrence
    Set occ = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Select an occurrence.")
   
    ' Assign the asset to the occurrence.
    occ.appearance = localAsset
   
End Sub

 

Philippe.

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 6
GeorgK
in reply to: philippe.leefsma

Hello Philippe,

 

thanks for the answer. I tried to change it for material. Could you help me to get it running?

 

Georg

 

Public Sub SetOccurrenceMaterial()
    Dim Name As String
    Name = "1.0120 St37k"

    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
   
    Dim localAsset As Asset
       
    On Error Resume Next
    Set localAsset = asmDoc.Assets.Item(Name)
    If Err Then
        On Error GoTo 0
       
        Dim assetLib As AssetLibrary
        ' Get the Autodesk Material Library.
        Set assetLib = ThisApplication.AssetLibraries.Item("AD121259-C03E-4A1D-92D8-59A22B4807AD")
       
        Dim libAsset As Asset
        Set libAsset = assetLib.MaterialAssets.Item(Name)
               
        Set localAsset = libAsset.CopyTo(asmDoc)
    End If
    On Error GoTo 0
         
    Dim occ As ComponentOccurrence
    Set occ = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Select an occurrence.")
   
    'How to change?
  Call asmDoc.BrowserPanes.ActivePane.TopNode.DoSelect
End Sub
Message 4 of 6
philippe.leefsma
in reply to: GeorgK

Hi Georg,

 

You need to set the asset to the occurrence.appearance property

 

occ.appearance = localAsset

 

The CommandManager.Pick method should return the selected occurrence or null if the user cancelled the selection.

 

Hope that helps,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 5 of 6
GeorgK
in reply to: philippe.leefsma

Hello Philippe,

 

thanks.

 

Cheers Georg

Message 6 of 6
gkniksch
in reply to: philippe.leefsma

This works great for changing the appearance, but how can I excute a similar macro that removes the appearance override?

 

Thanks!

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

Post to forums  

Autodesk Design & Make Report