Investigating Asset Libraries Progamatically

Top  Previous  Next

You can loop over all the asset libraries loaded into Inventor like this:


   CComPtr<AssetLibraries> pAssLibs ;

   HRESULT hRes = pInvApp->get_AssetLibraries (&pAssLibs) ;

   if (FAILED(hRes) || (pAssLibs == nullptr)) {

       ShowCOMError (hRes,L"Could not get asset libraries");

       return ;



   long iNumAssLibs ;

   pAssLibs->get_Count(&iNumAssLibs) ;

   WalertBoxA ("There are %d asset libraries",iNumAssLibs) ;


   for (long iLib = 1 ; iLib <= iNumAssLibs ; iLib++) {

       CComPtr<AssetLibrary> pAssLib ;

       pAssLibs->get_Item (CComVariant(iLib),&pAssLib) ;


       CComBSTR bstrDisplayName,bstrFullFileName,bstrInternalName ;

       pAssLib->get_DisplayName (&bstrDisplayName) ;

       pAssLib->get_FullFileName (&bstrFullFileName) ;

       pAssLib->get_InternalName (&bstrInternalName) ;


       TRACE (L"Lib %d has <%s>,  <%s>,  <%s>.\n",iLib,bstrDisplayName,bstrFullFileName,bstrInternalName) ;



And you'll get a result something like this:


Lib 1 has <Autodesk Material Library>,  <C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\2015\PhysicalMaterial.adsklib>,  <AD121259-C03E-4A1D-92D8-59A22B4807AD>.

Lib 2 has <Autodesk Appearance Library>,  <C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\2015\assetlibrary_base.adsklib>,  <314DE259-5443-4621-BFBD-1730C6CC9AE9>.

Lib 3 has <Favorites>,  <C:\Users\Owen\AppData\Roaming\Autodesk\Inventor 2015\FavoriteMaterials.adsklib>,  <D07F930C-485A-4658-AD69-C91D17FEB99B>.

Lib 4 has <Inventor Material Library>,  <C:\Users\Public\Documents\Autodesk\Inventor 2015\Design Data\Materials\InventorMaterialLibrary.adsklib>,  <AFEFC330-5E61-4E24-814F-AE810148B79D>.


The internal name is a GUID it looks like.


Note that it seems that you need to have loaded at least one part, else the assets can be null pointers. It seems like loading a part loads the materials.


Once you have an asset lib you can loop over its contents like this:


       CComPtr<AssetsEnumerator> pAssEnum ;

       pAssLib->get_MaterialAssets (&pAssEnum) ;


       const long ikNumAssets = pAssEnum->Count ;


       for (long iAss = 1 ; iAss <= ikNumAssets ; iAss++) {

           CComPtr<Asset> pAsset ;

           pAssEnum->get_Item (CComVariant(iAss),&pAsset) ;


           CComBSTR bstrDispName,bstrName,bstrCatName ;

           pAsset->get_DisplayName (&bstrDispName) ;

           pAsset->get_Name (&bstrName) ;

           pAsset->get_CategoryName (&bstrCatName) ;

           TRACE (L" DisplayName=<%s> Name=<%s> CatName=<%s>\n",

                  bstrDispName,bstrName,bstrCatName) ;



And the results will look something like this:


DisplayName=<GFRC> Name=<Material-010> CatName=<Concrete>

DisplayName=<Gold> Name=<Material-068> CatName=<Metal>

DisplayName=<Iron, Ductile> Name=<Material-071> CatName=<Metal>

DisplayName=<Lead> Name=<Material-072> CatName=<Metal>

DisplayName=<Silver> Name=<Material-076> CatName=<Metal>

DisplayName=<Steel> Name=<Material-077> CatName=<Metal>

DisplayName=<Steel, Galvanized> Name=<Material-079> CatName=<Metal>


I think the display name will change from language to language, but I need to investigate further. Categories are clearly Metal, Concrete, Wood etc.


Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)