Inventor Command Line Reference
The commandLine
parameter of an Activity lets you specify the executable (InventorCoreConsole.Exe - the Inventor Core Console) that must be run and the command line arguments that must be passed when a WorkItem executes the Activity. In addition to the supported standard parameters you can specify custom arguments, which can be accessed from within custom plugins.
Standard parameters
The following table lists standard parameters. The first four can be used together with Inventor Core Console.
Parameter | Value | Meaning |
---|---|---|
/i | input_file | The drawing file path, will be automatically opened by Inventor |
/s | script_file | The path to the iLogic script file to be executed |
/p | (switch, without value) | Create and activate default project |
/al | plugin_to_use | The path to the plugin to be executed by Inventor |
/iv | (switch, without value) | Open the input file in invisible mode |
/v | (switch, without value) | Not applicable |
/isolate | registry_root_key user_data_path (two values) | Not applicable |
/h | (switch, without value) | Not applicable |
/? | (switch, without value) | Not applicable |
Calling external iLogic script
A custom script is called by specifying /s on the command line, e.g.
InventorCoreConsole.exe /s "custom_script.iLogicVb"
Calling a custom plugin
Another way of using Inventor Core Console is to call a custom plugin, e.g.
InventorCoreConsole.exe /al "plugin_to_use" /i "input_file.ipt"
One can even parameterize the custom plugin by adding custom command line arguments, e.g.
InventorCoreConsole.exe /al “plugin_to_use” /i “input_file.ipt” command subcommand /customArg1 value1 /customSwitch /customArg2 value2a value2b /additionalValues value1,value2,value3
Command line arguments passed to the plugin are pre-processed and stored in a NameValueMap object.
All arguments other than predefined (i.e. options other than /i, /s, /p, /v, /al, /isolate, /h, /? and corresponding values) are available in the NameValueMap
object.
Accessing command line arguments by position
Command line arguments are split by white space characters. One way of accessing these arguments is to access individual tokens by their position on the command line. The previous example is split into these ten tokens:
Key | Value |
---|---|
“_1” | “command” |
“_2” | “subcommand” |
“_3” | “/customArg1” |
“_4” | “value1” |
“_5” | “/customSwitch” |
“_6” | “/customArg2” |
“_7” | “value2a” |
“_8” | “value2b” |
“_9” | “/additionalValues” |
“_10” | “value1,value2,value3” |
You can access the individual token, e.g. map.Item["_6"]
. The returned value in this case is "customArg2"
.
Accessing command line arguments by name
An alternative and more robust way of accessing command line arguments is to access them by name. The command line is interpreted in the following way:
- each token starting with a slash prefix
/
represents a parameter name, e.g./customArg2
- the next tokens (not starting with slash prefix) represent parameter values, e.g.
value2a
- parameters can be multi-value - individual values are separated by a space or by a comma, e.g.
value2a value2b
orvalue1,value2,value3
- parameters without value are considered to be switches, e.g.
/customSwitch
. Their value is defined to be"true"
.
The previous example is interpreted in the following way:
Key | Value |
---|---|
“customArg1” | “value1” |
“customSwitch” | “true” |
“customArg2” | “value2a value2b” |
“additionalValues” | “value1,value2,value3” |
Use extension methods to parse command line parameters
You can install the utility NuGet Autodesk.Forge.DesignAutomation.Inventor.Utils <https://www-1.nuget.org/packages/Autodesk.Forge.DesignAutomation.Inventor.Utils/>. Through your NuGet manager.
You can use extension methods from NameValueMapExtension
to further parse command line arguments.
The documentation of the extension class is available here.
NameValueMapExtension is a class that is designed to extend the functionality of the NameValueMap
.
It does not change the functionality or the underlying data of the original map but it rather makes working with the map’s data easier.
Since NameValueMapExtension
is an extension class there is no need to initialize it in any way. After you install the Utility nuget and you can use extension
methods on NameValueMap right away.
Consider the following command line arguments:
/i "input_file" /al "plugin_to_use" /s "script_file" /p \
command subcommand /property val val2 \
/verbose /file file.txt /additionalValue1 1
First, lets include the extension helper into our project:
using Autodesk.Forge.DesignAutomation.Inventor.Utils.Helpers;
You can now use "additionalValue1"
as an index to get the intValue:
int intValue = nameValueMap.AsInt("additionalValue1")
// Do something ...
The same index can also be used as a string
string strValue = nameValueMap.AsString("additionalValue1")
// Do something ...
You can even get a collection of values. Lets consider the following command line arguments:
/i "input_file" /al "plugin_to_use" /s "script_file" /p \
command subcommand /property val val2 /verbose /file file.txt \
/collection 1.33, 2.5, 3.7, 41.5, 133.7, 650.832, 7.145
You can then simply call one of the As[Type]Collection() extension methods to get the collection of the data on the given index. The following code
double[] doubleCollection = nameValueMap.AsDoubleCollection("/collection");
foreach (double value in doubleCollection)
{
Console.writeLine(value)
}
yields the following output:
1.33
2.5
3.7
41.5
133.7
650.832
7.145
Please note that the data must be convertible to the desired type. The value "3.15"
can be converted to double
and string
but the value "value"
can only be represented as a string
.
The As[type]
and As[type]Collection
extension methods are avaible for 5 basic types
string
int
double
bool
enum
Lets use the following example to demonstrate both the bool
and enum
use cases:
/i "input_file" /al "plugin_to_use" /s "script_file" /p \
command subcommand /property val val2 \
/verbose /file file.txt /additionalValue1 TRUE \
/additionalValue2 VALUE_TWO
Consider the following custom enum:
public enum MyEnum
{
VALUE_ONE,
VALUE_TWO,
VALUE_THREE,
VALUE_FOUR,
VALUE_FIVE
}
Now, we can access the properties using the following way:
bool boolValue = nameValueMap.AsBool("additionalValue1")
// boolValue is true
// Do something ...
MyEnum enumValue = nameValueMap.AsEnum<MyEnum>("additionalValue2")
// the variable enumValue is set to VALUE_TWO
// Do something ...
Last but not least, there is a pair of generic extension methods that you can use to try to convert the value to a different type that implements the IConvertible interface - link to https://docs.microsoft.com/en-us/dotnet/api/system.iconvertible?view=netcore-3.1.
These methods are:
TryGetValueAs<type>(string index, out type outValue)
GetValueAsCollection<type>(string index)
Exceptions
All extension methods except TryGetValueAs
can raise two types of exceptions:
InvalidValueTypeException
- the conversion fails due to incompatible types ("value"
toint
for example)KeyNotFoundException
- the requested index was not found in the map
The method TryGetValueAs
on the other hand is exception safe and returns a boolean success value.
In the unsuccessful case the outValue is set to the default value of the given type.
Example
The following example demonstrates the use of the new command line functionality.
Let us create a new Activity with the following command line:
$(engine.path)\\InventorCoreConsole.exe /al "$(appbundles[{Constants.Activity.Id}].path)" \
/i "$(args[{Constants.Parameters.InventorDoc}].path)" \
/customCollection "$(args[{Constants.Parameters.CollectionParam}].value)" \
/customSwitch \
/customArg customValue \
/intParam "$(args[{Constants.Parameters.IntParam}].value)" \
/doubleParam "$(args[{Constants.Parameters.DoubleParam}].value)"
The activity calls a custom plugin wrapped in an app bundle. The input for the plugin is a given inventor document supplemented by the list of five additional command line arguments. Two of these arguments are hardcoded in the command line definition - customSwitch and customArg. The remaining three arguments are parameterized and their values are defined by the work item (customCollection, intParam and doubleParam).
The RunWithArguments(Document doc, NameValueMap map) entry method of app bundle custom plugin is called by Inventor. Custom arguments are included in the map object. One can access them using NameValueMapExtension in the following way:
bool customSwitch = map.HasKey("customSwitch");
int intParam = map.AsInt("intParam");
double doubleParam = map.AsDouble("doubleParam");
var customCollection = map.AsStringCollection("customCollection");
var customArg = map.Item["customArg"];