Setting the active material library

Setting the active material library

cstephens58F4Q
Contributor Contributor
865 Views
1 Reply
Message 1 of 2

Setting the active material library

cstephens58F4Q
Contributor
Contributor

What is the best way to set the active Material library when creating parts using the API. I have the materials being selected but I cant get them to pull from the Material Library in the Project file the API is being used within.

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

A.Acheson
Mentor
Mentor

The API file has a material sample written in VBA shown here to retrieve all asset libraries and all materials. 

Try this code out to check local document for material, if not found then retrieve material from Asset Library and copy to local . This Application.ActvematerialLibrary is optional. It will just set the libary drop down active from the local document. 

    Dim oDoc As PartDocument = ThisApplication.ActiveDocument

    Dim assetLib As AssetLibrary  = ThisApplication.AssetLibraries.Item("Inventor Material Library")
 	
	ThisApplication.ActiveMaterialLibrary = assetLib
   
    Dim MaterialName As String = "Gold"
   
    Try
	Dim localMaterial As MaterialAsset = oDoc.MaterialAssets.Item(MaterialName)
 	Catch
    Dim libMaterial As MaterialAsset = assetLib.MaterialAssets.Item(MaterialName)
	libMaterial.CopyTo(oDoc)
	End Try
	
	oDoc.ActiveMaterial = oDoc.MaterialAssets.Item(MaterialName)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan