Cannot access fundamental API objects (e.g. MaterialManager)

Cannot access fundamental API objects (e.g. MaterialManager)

HishamWQ298
Explorer Explorer
222 Views
3 Replies
Message 1 of 4

Cannot access fundamental API objects (e.g. MaterialManager)

HishamWQ298
Explorer
Explorer

Hello, hope you're doing well
I'm having some issues with iLogic scripts, specifically with accessing MaterialManager. The block in my script which calls them out is:

    ' Attempt to access MaterialManager
    Try
        oMaterialManager = oApp.MaterialManager
        If oMaterialManager Is Nothing Then
            MsgBox("Test Result: MaterialManager is Nothing after trying to access it.", MsgBoxStyle.Critical, "Debug: MaterialManager Test")
            Exit Sub
        End If
    Catch ex As Exception
        MsgBox("Test Result: CRITICAL ERROR accessing MaterialManager from Application: " & ex.Message, MsgBoxStyle.Critical, "Debug: MaterialManager Test")
        Exit Sub
    End Try

 

When I run the script, I get the following error:

HishamWQ298_0-1748384315261.png

 

I imported Inventor at the beginning of the script too

I can share the entire script but what would be the cause for such a fundamental issue?

 

Build: 162, Release: 2025.0.1 - Date: Mon 05/13/2024

Thanks, 
Hisham

0 Likes
Accepted solutions (1)
223 Views
3 Replies
Replies (3)
Message 2 of 4

mat_hijs
Collaborator
Collaborator
Accepted solution

Application.MaterialManager simply doesn't exist, as you can see here: https://help.autodesk.com/view/INVNTOR/2026/ENU/?guid=GUID-Application

I suspect this code was written by AI, that often causes methods or properties that don't exist to be called. If you post what you're trying to to someone on this forum can probably guide you in the right direction.

0 Likes
Message 3 of 4

HishamWQ298
Explorer
Explorer

Oh my god the absolute betrayal I feel now... I guess that's what I get for trusting AI tools too much this early, but yeah it was written by AI
What I'm trying to do is loop through an excel spreadsheet and create materials in an existing library based on a template material, with small changes. Appreciate any guidance on existing resources to achieve this. 
Thanks Mat 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

In Inventor, specifications for both 'materials' and 'appearances' are stored in objects known as an assets.

Consistent Materials (Materials and Appearances) 

What we do have is external asset libraries (each library is a single file in disk), and each model document can have its own collection assets.

An asset library can store both materials and appearances in it at the same time, but they just store the specifications for those materials and appearances, and do not offer methods for creating new assets.  If we want to create a new asset, we have to either copy an existing one, then modify it, or use the Assets.Add method, which is only available from within an existing part document.  Once we create a local asset within a document, we can copy it up into an external asset library, which will make it available to all other documents using the Asset.CopyTo method, and specifying the AssetLibrary object that we want to copy it into.

 

Below are some links to the Inventor API online help for many of the objects involved.

AssetLibraries (a collection of individual AssetLibrary objects)

AssetLibrary (a single AssetLibrary object, potentially containing specs for multiple Asset objects)

Assets (the 'local' collection of assets stored in an Inventor model Document)

Asset (can be the specs for a single material, a single appearance, or a single physical properties)

MaterialAsset  (a sub-type of the regular Asset type, specifically for a material, and has associations with a single appearance asset and a single physical property asset)

AssetValue (a base type for a bunch of more specific sub-types, each designed for storing a specific type of value...Each Asset has multiple AssetValues as its Items)

Here are some more...

Application.AssetLibraries 

Application.ActiveAppearanceLibrary 

Application.ActiveMaterialLibrary 

PartDocument.ActiveAppearance 

PartDocument.ActiveMaterial 

PartDocument.Assets 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)