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: 

Material Asset Inventor 2014

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
saseendrankombath
2292 Views, 8 Replies

Material Asset Inventor 2014

Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
    
    Dim material As material
    For Each material In oPartDoc.Materials
        Debug.Print material.Name 'This prints all names of material in the part Document (including local material)
    Next
    Debug.Print "===================================================="
    Dim matAsset As MaterialAsset
    For Each matAsset In oPartDoc.MaterialAssets 'This prints only the local material
        Debug.Print matAsset.DisplayName
    Next

 

Material and materials are working well with Inventor 2014, but while writing code material and materials are not accessible thru dropdown and we have to type them.

Inventor 2014 API major change is material to material assets and assets are available thru dropdown while writing code.

Is it possible to get all the material names of part document using asset method? If Yes, Please explain. Or we have to use the old API method of material and materials by typing full (without selecting from drop down) 

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: saseendrankombath

Yes ,you can add all materials to dropdown using the below code.here is the code.may be this will helps you.

 

 

  Dim oDoc As Document
        oDoc = inventorApp.Documents.Open("F:\inventor\Proof Of Con\Cube\Cube_update.ipt")
        Dim oDocument As ApprenticeServerDocument
        oDocument = inventorApp.ActiveDocument

        Dim oMaterials As Materials = oDocument.Materials
        Dim mat As Material
        For Each mat In oMaterials
            DropDownList1.Items.Add(mat.Name)
        Next

 

Message 3 of 9
saseendrankombath
in reply to: Anonymous

This is the same result of the first portion of my code which I Posted and I was using the same code for long time. My question is how to use material asset to produce the same result in Inventor 2014 

Message 4 of 9

Hi,

 

You can also get them from the "Inventor Material Library" asset library:

    Dim assetLib As AssetLibrary
    Set assetLib = ThisApplication.AssetLibraries("Inventor Material Library")
    
    Dim matAsset As MaterialAsset
    For Each matAsset In assetLib.MaterialAssets
        Debug.Print matAsset.DisplayName
    Next

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 9

Thank you for your replay

I have tried this also. This gives only the global level material and the second part of my code gives only the local material. But the old type code i.e. first part of my code posted gives both global and local material list. How can we get the same result when we change material to material asset?

Message 6 of 9

My requirement is to reprduce a combobox same like iProperties - Physical - Material in my iProperty editor Add-Inn

This is done by using the below code. 

Me.cmbMaterial.Items.Clear()
Dim oMaterial As Inventor.Material
            For Each oMaterial In oPartDoc.Materials
                Me.cmbMaterial.Items.Add(oMaterial.Name)
            Next
strMaterialName = oPartDoc.ComponentDefinition.Material.Name
Me.cmbMaterial.Text = strMaterialName

 This works fine and gives the result same as iProperties - Physical - Material

If use Material asset in Inventor 2014 I am not able to produce the same. If I add local material with a workarrount (see code below) some material will duplicate in the list and wil not be in an order like before.

 

Me.cmbMaterial.Items.Clear()
Dim oMaterial As Inventor.MaterialAsset
'Add Global materials
            For Each oMaterial In m_inventorApplication.ActiveMaterialLibrary.MaterialAssets
                Me.cmbMaterial.Items.Add(oMaterial.DisplayName)
            Next
            'Add local materials
            For Each material In oPartDoc.MaterialAssets
                Me.cmbMaterial.Items.Add(material.DisplayName)
            Next
strMaterialName = oPartDoc.ActiveMaterial.DisplayName
            Me.cmbMaterial.Text = strMaterialName

How can I reproduce the result of first code with the changes in Inventor 2014 material asset?

 

Message 7 of 9

You may aggregate assets from both sources in the temporary sorted collection with assets names as unique string keys (sorted dictionary).  This guarantees you the absence of duplicated members in your list.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 8 of 9

Thank you Vladimir

Message 9 of 9
krisnakumar
in reply to: adam.nagy

here I am stuck to create a new custom library for my custom material.. Please help me to achieve this.. 

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

Post to forums  

Autodesk Design & Make Report