1 Mar 2023

Debug and optimize iLogic on Design Automation

1) Debug

The documentation talks about setting the iLogic debugging options in your app bundle code to get more information printed in the work item's report file: 
https://aps.autodesk.com/en/docs/design-automation/v3/developers_guide/inventor_specific/ilogic-logging/ 

The same options (Trace, Info, etc) are also exposed in the command line of InventorCoreConsole.exe under the /iLogicVerbosity parameter - see in the above picture highlighted in orange the extra info we get using the /iLogicVerbosity Trace command line parameter.

2) Optimize

When using the OK/Cancel/Apply option in an iLogic Form there is an optimization that will delay the running of iLogic rules that are triggered by parameter modifications until the user clicks Apply.

iLogic Form Ok / Cancel / Appply

The same can be achieved using the IiLogicAutomation interface's EnterDelayedRuleRunningModeExitDelayedRuleRunningMode functions.
It would also enable you to not let any of the triggered rules run if you don't need them (e.g. perhaps if one of the parameter updates failed): just pass false to ExitDelayedRuleRunningMode as input parameter.

For testing purposes I used the Design Automation tutorial and modified its ChangeParameters function the following way:

public void ChangeParameters(Document doc)
{
  var theParams = GetParameters(doc);

  dynamic iLogicAddIn = m_server.ApplicationAddIns.ItemById["{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"];
  iLogicAddIn.Automation.EnterDelayedRuleRunningMode();
      
  Dictionary<string, string> parameters = JsonConvert.DeserializeObject<Dictionary<string, string>>(System.IO.File.ReadAllText("params.json"));
  foreach (KeyValuePair<string, string> entry in parameters)
  {
    var keyName = entry.Key.ToLower();
    try
    {
      Parameter param = theParams[keyName];
      param.Expression = entry.Value;
      LogTrace($"Updated {keyName}");
    }
    catch (Exception e) { LogTrace("Cannot update {0}: {1}", keyName, e.Message); }
  }
      
  iLogicAddIn.Automation.ExitDelayedRuleRunningMode(true);
  doc.Update();
}

See results in the picture on top. 

Related Article