24 Nov 2020

Pass custom command-line arguments from WorkItem

You can only set the commandLine in the Activity, so how could you add job-specific arguments to it when starting the WorkItem?

Many people simply place all information needed to drive the model configuration in a json file and pass that to the WorkItem - just like in the LearnForge tutorial.

However, you could pass additional information through the command line as well. 

You're probably familiar with the 3 HTTP verbs that are used for the input/output arguments: GET, POST, PUT  
But READ is also available, and that's what we are going to use here.
Note: READ is not an official HTTP verb but an extra one available in Design Automation.

There is a video showing this solution listed in this blog post, named "Design Automation for Inventor" (relevant section starts at 7:40 in the video)

You can simply add a single extra parameter to the Activity to provide all additional command-line switches and their values:

{
  "commandLine": [
    "$(engine.path)\\InventorCoreConsole.exe /al \"$(appbundles[DaSample].path)\" /i \"$(args[inputFile].path)\" $(args[extraParams].value)"
  ],
  "parameters": {
    "inputFile": {
      "verb": "get",
      "localName": "inputFile.ipt"
    },
    "outputFile": {
      "verb": "put",
      "localName": "outputFile.ipt"
    },
    "extraParams": {
      "verb": "read"
    }
  },
  "id": "rGm0mO9jVSsD2yBEDk9MRtXQTwsa61y0.DaSample+prod",
  "engine": "Autodesk.Inventor+24",
  "appbundles": ["rGm0mO9jVSsD2yBEDk9MRtXQTwsa61y0.DaSample+prod"],
  "description": "Running iLogic Rule",
  "version": 1
}

When using the READ verb for a parameter, then instead of providing a URL, you would have to provide a string value

{
  "inputFile": {
    "url": "<url to file>"
  },
  "outputFile": {
    "url": "<url to file>"
  },
  "extraParams": "/width 10 /height 20"
}

If you are using .NET (e.g. the "Interaction" project provided by the Design Automation for Inventor Visual Studio Project template) then you'd have to use StringArgument like this:

private static Dictionary<string, IArgument> GetWorkItemArgs()
{
    return new Dictionary<string, IArgument>
    {
        {
            Constants.Parameters.InputFile,
            new XrefTreeArgument()
            {
                Url = "<url of the input file>"
            }
        },
        {
            Constants.Parameters.OutputFile,
            new XrefTreeArgument()
            {
                Url = "<url of the output file>"
            }
        },
        {
            Constants.Parameters.ExtraParams,
            new StringArgument()
            {
                Value = "/width 10 /height 20"
            }
        }
    };
}

 

Related Article