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)
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
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
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
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,
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?
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?
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.
here I am stuck to create a new custom library for my custom material.. Please help me to achieve this..