Copy material to another library

<?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:

Mylibrary

 


Comments

3 responses to “Copy material to another library”

  1. plandry@technip.com Avatar
    plandry@technip.com

    Hello,
    Under INVENTOR 2015, I wish to use ASSETLIBRARIES, ASSETS and so on in Visual STUDIO instead of VBA, I can’t access to those object. Which reference must I include in my project to let me use them ?
    My problem is to check that all material libraries I use under INVENTOR can load all styles needed by each material.
    Thanks for your help
    Regards

  2. Hi,
    Have a look at this: http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=17325174 Those objects should be part of the Inventor interop assembly
    If you have more questions then it might be better to use the Inventor Customisation forum:
    http://forums.autodesk.com/t5/inventor-customization/bd-p/120
    Cheers,
    Adam

  3. plandry@technip.com Avatar
    plandry@technip.com

    Hi
    Thanks for the answer.
    However, I added the Inventor interop assembly as reference in my project but I didn’t find those objects. I haven’t any problems if I do it in VBA.
    I switch in the forum as you advised me.
    Regards
    Philippe

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading