Export and import iLogic rules
Wednesday, March 4, 2026Internal iLogic rules are stored directly inside Inventor documents (parts, assemblies, drawings). This is convenient — the rule travels with the file — but it creates a major problem: these rules cannot be placed under version control with a tool like Git.
By exporting rules as text files (.iLogicVB), several possibilities open up:
- Track changes with Git: Git is a version control tool used by the vast majority of developers. It keeps a complete history of every file, making it possible to compare versions, roll back in case of error, and collaborate on the same rules. It also acts as a reliable backup: as long as the repository is synchronized with a remote server, nothing is lost. Using Git for iLogic rules means applying the same practices as professional developers.
- Edit in a modern editor such as Visual Studio Code, with advanced search and the ability to pair the editor with an AI assistant to speed up code writing.
Internal rules remain essential
Internal rules have specific advantages that external rules cannot reproduce:
- Direct access to parameters: in the built-in editor, model parameter names appear as variables (displayed in blue). You can read and modify them without going through the API, which makes code more readable.
- Targeted automatic triggering: an internal rule can be associated with a specific parameter change via Event Triggers. For example, modifying the
Lengthparameter can automatically trigger a rule that recalculates other dimensions. External rules can also be assigned to triggers, but only for global events like "any parameter change", without filtering on a specific parameter.
Editing in an external editor does not replace the built-in editor: the two approaches are complementary. The Inventor iLogic editor provides interactive assistants that let you browse the model and directly select parameters, iProperties, or assembly components. It also supplies a library of code snippets for common operations. You can use it to build model-related calls and configure triggers, then switch to an external editor for the rest of the logic.
Export / import procedure
The principle is simple, but requires discipline:
- After each modification in Inventor's built-in editor, run the export rule to synchronize the files on disk.
- After each modification in the external editor, run the import rule to inject changes into the Inventor document.
Remember to synchronize each time, otherwise you risk overwriting changes made on one side with the other.
Export rule
This rule exports all iLogic rules from the active document as .iLogicVB files into a folder. It excludes itself from the export to avoid an unnecessary loop.
' Export all iLogic rules from the active document
Dim doc As Document = ThisDoc.Document
Dim iLogicAuto As Object = Nothing
Try
iLogicAuto = ThisApplication.ApplicationAddIns.ItemById( _
"{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}").Automation
Catch
MessageBox.Show("iLogic Automation not available.")
Return
End Try
Dim rules = iLogicAuto.Rules(doc)
Dim exportFolder As String = "C:\MyProject\"
If Not System.IO.Directory.Exists(exportFolder) Then
System.IO.Directory.CreateDirectory(exportFolder)
End If
For Each r In rules
If r.Name = "Export rules" Then Continue For
Dim filePath As String = System.IO.Path.Combine(exportFolder, r.Name & ".iLogicVB")
System.IO.File.WriteAllText(filePath, r.Text)
Next
MessageBox.Show("Export complete: " & exportFolder)
Import rule
This rule scans .iLogicVB files from the folder and updates existing rules in the document. If a rule does not exist yet, it is created automatically.
' Import / update iLogic rules from a folder
Dim doc As Document = ThisDoc.Document
Dim iLogicAuto As Object = Nothing
Try
iLogicAuto = ThisApplication.ApplicationAddIns.ItemById( _
"{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}").Automation
Catch
MessageBox.Show("iLogic Automation not available.")
Return
End Try
' Folder containing .iLogicVB or .txt files
Dim importFolder As String = "C:\MyProject\"
If Not System.IO.Directory.Exists(importFolder) Then
MessageBox.Show("Folder does not exist: " & importFolder)
Return
End If
' Retrieve files
Dim files = System.IO.Directory.GetFiles(importFolder, "*.iLogicVB")
If files.Length = 0 Then
MessageBox.Show("No .iLogicVB files found.")
Return
End If
For Each file In files
Dim ruleName As String = System.IO.Path.GetFileNameWithoutExtension(File)
Dim ruleText As String = System.IO.File.ReadAllText(File)
Dim existingRule = iLogicAuto.GetRule(doc, ruleName)
If existingRule Is Nothing Then
' Create a new rule
iLogicAuto.AddRule(doc, ruleName, ruleText)
Else
' Update the existing rule
existingRule.Text = ruleText
End If
Next
MessageBox.Show("Import / update complete.")
Note that you can do the same thing with VBA macros, although I would advise against writing new code on that platform as it has been obsolete for a long time. However, it can be useful for migrating existing macros to iLogic rules.
Need an Inventor (iLogic, .NET, VBA, C++) or Fusion 360 (Python, C++) development? Contact me for a free quote.