21 Mar 2020

Run() vs RunWithArguments()

In case of AppBundles for Design Automation API for Inventor there are two entry points depending on the arguments in the commandLine parameter of the Activity that is using the AppBundle.

- Run(Document doc) is called if the commandLine only contains arguments which are handled by InventorCoreConsole. Currently these are:
/al : path to the AppBundle to load
/i : path to the document to load
/s : path to the script file with code to run (see Run command from an AutoCAD AppBundle and Run iLogic Rule without AppBundle
e.g.: $(engine.path)\\InventorCoreConsole.exe /i $(args[inputFile].path) /s $(settings[script].path)

- RunWithArguments(Document doc, NameValueMap mapis called if there are any additional custom arguments passed to InventorCoreConsole
e.g.: $(engine.path)\\InventorCoreConsole.exe /i $(args[inputFile].path) /s $(settings[script].path) params.json
e.g.: $(engine.path)\\InventorCoreConsole.exe /i $(args[inputFile].path) /s $(settings[script].path) /j $(args[inputParams].path)

The additional command line arguments will be available in the map variable with key values going "_1", "_2" ... 
e.g. in case of such a commandLine

"$(engine.path)\\InventorCoreConsole.exe /al $(appbundles[{Constants.Activity.Id}].path) /j $(args[{Constants.Parameters.InputJson}].path) /k \"just a test\""

... the following will be listed in the WorkItem's report file:

[03/21/2020 13:18:39]     InventorCoreConsole.exe Information: 0 : RunWithArguments called
[03/21/2020 13:18:39]     InventorCoreConsole.exe Information: 0 : List of values in 'map':
[03/21/2020 13:18:39]     InventorCoreConsole.exe Information: 0 : _1 = /j
[03/21/2020 13:18:39]     InventorCoreConsole.exe Information: 0 : _2 = T:\Aces\Jobs\9fbed84f067b4181b6f3d38cc447ab48\input.json
[03/21/2020 13:18:39]     InventorCoreConsole.exe Information: 0 : _3 = /k
[03/21/2020 13:18:39]     InventorCoreConsole.exe Information: 0 : _4 = just a test

This is the code used in the AppBundle to print the above values: 

public void RunWithArguments(Document doc, NameValueMap map)
{
    LogTrace("RunWithArguments called");

    Trace.TraceInformation("List of values in 'map':");

    for (int i = 1; i <= map.Count; i++)
    {
        Trace.TraceInformation($"{map.Name[i]} = {map.Item[i]}");
    }
}

There is also another way to read the command line arguments if you prefer - see Handle command line arguments

Related Article