15 Jun 2020

Get modeling error details from Inventor

When working on the desktop it's easy to see when something goes wrong, but when doing the same operations on a server without user interaction, you might need some help to see what the problem is.

Inside Inventor there is something called the Error Manager, which also shows messages in the User Interface:

ErrorManager object

Using the ErrorManager object in the Inventor API you can get access to that same information. This might help you return from a failed model update quicker and enable you to provide better information for the users about what went wrong.

As an example, I have a WorkItem that takes an Inventor part document with a parameter called "height" driving an extrusion. The following code will set that to 0 and then it will print the information found in the ErrorManager object:

public void RunWithArguments(Document doc, NameValueMap map)
{
    var em = inventorApplication.ErrorManager;
    LogTrace($"Checking ErrorManager before problem");
    LogTrace($"HasErrors = {em.HasErrors}");
    LogTrace($"HasWarnings = {em.HasWarnings}");
    LogTrace($"AllMessages = {em.AllMessages}");

    PartDocument pd = doc as PartDocument;
    pd.ComponentDefinition.Parameters["height"].Expression = "0";
    pd.Update2();

    LogTrace($"Checking ErrorManager after problem");
    LogTrace($"HasErrors = {em.HasErrors}");
    LogTrace($"HasWarnings = {em.HasWarnings}");
    LogTrace($"AllMessages = {em.AllMessages}");
}

The relevant part of the report from the WorkItem:

[06/15/2020 10:34:06]     InventorCoreConsole.exe Information: 0 : RunWithArguments called
[06/15/2020 10:34:06]     InventorCoreConsole.exe Information: 0 : Checking ErrorManager before problem
[06/15/2020 10:34:06]     InventorCoreConsole.exe Information: 0 : HasErrors = False
[06/15/2020 10:34:06]     InventorCoreConsole.exe Information: 0 : HasWarnings = False
[06/15/2020 10:34:06]     InventorCoreConsole.exe Information: 0 : AllMessages = <ErrorsAndWarnings/>
[06/15/2020 10:34:07]     InventorCoreConsole.exe Information: 0 : Checking ErrorManager after problem
[06/15/2020 10:34:07]     InventorCoreConsole.exe Information: 0 : HasErrors = False
[06/15/2020 10:34:07]     InventorCoreConsole.exe Information: 0 : HasWarnings = True
[06/15/2020 10:34:07]     InventorCoreConsole.exe Information: 0 : AllMessages = <ErrorsAndWarnings><Warning Message="HiddenBox.ipt: Errors occurred during update"><Error Message="Extrusion1: Could not build this Extrusion"><Error Message="Extrusion distance is zero.  Use Edit Extruded Feature to change the extrusion distance."/></Error></Warning></ErrorsAndWarnings>
[06/15/2020 10:34:07]     InventorCoreConsole.exe Warning: 0 : Inventor message: HiddenBox.ipt: Errors occurred during update
[06/15/2020 10:34:07]     InventorCoreConsole.exe Warning: 0 : Inventor inner xml: <Error Message="Extrusion1: Could not build this Extrusion"><Error Message="Extrusion distance is zero.  Use Edit Extruded Feature to change the extrusion distance." /></Error>

 

Related Article