30 Oct 2019

Run iLogic Rule without AppBundle

The way you usually work with Design Automation API is that you:
1) Create an AppBundle
2) Create an Activity which uses the AppBundle
3) Run a WorkItem based on the Activity

However, if you want to just take advantage of some iLogic code available in the documents you are working with, or want to just execute some other code, you can do it.
You can pass it as a parameter to the commandLine value of your Activity through the /s param

Activity:

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

The settings.script.value contains the code that I want to run and can reference it from the commandLine parameter through $(settings[script].path) and can pass it after the /s command line param. I will use this Activity with a document that has an iLogic Rule called "MyRule" and I will run this. 

The code we are providing under settings.script.value could be any VB.NET code that could be used inside an iLogic Rule - so instead of running "MyRule" residing in the document, we could do the whole thing via the activity. In that case, settings.script.value could be (using \n for line break):

"Trace.TraceInformation(\"Start of MyScript\")\n
Trace.TraceInformation(\"Setting height to 2 in\")\n
Parameter(\"height\") = \"2 in\"\n
Trace.TraceInformation(\"Updating document\")\n
InventorVb.DocumentUpdate()\n
Trace.TraceInformation(\"Saving changes\")\n
ThisDoc.Save()\n
Trace.TraceInformation(\"End of MyScript\")" 

WorkItem:

{
  "inputFile": {
    "verb": "get",
    "localName": "inputFile.ipt",
    "url": "https://developer.api.autodesk.com/oss/v2/buckets/adam_poc/objects/Box_With_iLogic.ipt",
    "headers": {
      "Authorization": "Bearer <access token>",
      "Content-type": "application/octet-stream"
    }
  },
  "outputFile": {
    "verb": "put",
    "localName": "inputFile.ipt",
    "url": "https://developer.api.autodesk.com/oss/v2/buckets/adam_poc/objects/Box_With_iLogic_Result.ipt",
    "headers": {
      "Authorization": "Bearer <access token>",
      "Content-type": "application/octet-stream"
    }
  }
}

The WorkItem is nothing special - we just pass in the URLs where DA can get the file from and place it back.

The Trace calls in the iLogic Rule will also show up in the WorkItem report, which is very useful to track what's going on:

...
[10/30/2019 17:16:07] InventorCoreConsole.exe Information: 0 : Start of MyRule
[10/30/2019 17:16:07] InventorCoreConsole.exe Information: 0 : Setting height to 2 in
[10/30/2019 17:16:07] InventorCoreConsole.exe Information: 0 : Updating document
[10/30/2019 17:16:07] InventorCoreConsole.exe Information: 0 : Saving changes
[10/30/2019 17:16:09] InventorCoreConsole.exe Information: 0 : End of MyRule
[10/30/2019 17:16:09] InventorCoreConsole.exe Information: 0 : Performing iLogic diagnostics...
[10/30/2019 17:16:09] InventorCoreConsole.exe Information: 0 : End of iLogic diagnostics...
...

 

Related Article