<?xml encoding=”UTF-8″>By Adam Nagy
This is quite similar to the solution shown here, with the main difference being that instead of adding the material to the document’s library, we add it to another external library.
Let’s say that my custom library is called “MyLibrary” and we want to add the material “Copper” to it. Then this VBA code should do the trick:
Sub CopyMaterialToMyLibrary()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim assetLibs As AssetLibraries
Set assetLibs = ThisApplication.AssetLibraries
Dim Name As String
Name = "Copper"
Dim localAsset As Asset
On Error Resume Next
Set localAsset = oDoc.Assets.Item(Name)
Dim assetLib As AssetLibrary
' Use name ...
'Set assetLib = assetLib("Autodesk Material Library")
' ... or ID
Set assetLib = assetLibs("AD121259-C03E-4A1D-92D8-59A22B4807AD")
Dim myAssetLib As AssetLibrary
Set myAssetLib = assetLibs("MyLibrary")
' Get an asset in the library
Dim libAsset As Asset
Set libAsset = assetLib.MaterialAssets(Name)
' Copy the asset to the other library
Set localAsset = libAsset.CopyTo(myAssetLib)
End Sub
Result:


Leave a Reply