16 Jul 2020

Use external iLogic Rules

As discussed in the Advanced techniques to write iLogic rules article, it's possible to store your code outside Inventor files and reference them from iLogic Rules

In iLogic search path for custom references we listed the paths that iLogic will search in order to find an external file reference, but we'll go through them here as well. 

1) The folder of the document running the rule

It is possible to provide a relative path as input for AddVbFile that will start from the location of the folder where the Inventor document running the iLogic Rule is.
Most of the time though people simply pass in the name of the file, in which case you just have to move the external VB file to the same folder where the Inventor document is.
This is probably the easiest way to making an external rule available for your documents on the Design Automation server 

2) The workspace path of the current project
3) The library paths of the current project

Have just written about using Projects to help Inventor with file resolution: Resolving referenced Inventor files
You can use the same mechanism to provide the path for your external VB file

4) The external rule directories set in Tools >> Options >> iLogic Configuration >> External Rule Directories
5) The reference path set in Tools >> Options >> iLogic Configuration >> iLogic Addin DLLs Directory

Not having a User Interface on Design Automation API for Inventor makes this a less obvious option.
However, you can use the FileOptions of the IiLogicAutomation interface provided by the iLogic Add-In.
This provides both ExternalRuleDirectories (paths for external VB or rule files) and AddinDirectory (for external dll's) 
You just have to reference Autodesk.iLogic.Interfaces.dll from your AppBundle code in order to use it:

public void AddExternalVbPath(string path)
  ApplicationAddIn addIn = inventorApplication.ApplicationAddIns.ItemById["{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}"];
  if (!addIn.Activated)
  IiLogicAutomation iLogicAuto = addIn.Automation;
  iLogicAuto.FileOptions.ExternalRuleDirectories = new string[] { path };

Note: the above solution should also work for iLogicVb.RunExternalRule(). Also, iLogic will not look into the subfolders of the above provided folders, so if the external files are in multiple folders and subfolders, you'll have to provide all of them.

Related Article