iLogic – Suppress/Unsuppress and Delete Rules

@ClintBrown3D Autodesk Inventor suppress delete ilogic rule

You may need an easy way to delete, suppress or unsuppress iLogic rules in an Inventor file. Generally you may want to delete internal rules in files, as running rules externally is often better (maybe I’ll explain my thoughts in another blog post). Doing this is quite simple, see the line of code below.

iLogicVb.Automation.DeleteRule(DocumentName, RuleName)

The reason I put this post together, is that I wanted an easy method that allowed me to suppress, unsuppress and delete rules from a handy interface.

I have written 2 utilities in this post, the first allows for individual rules to be suppresses/unsuppressed/deleted, the second rule suppresses or unsuppresses all of the rules in a file.

The animated GIF below shows my first piece of code in action:

Inventor iLogic Delete Suppress Rule

As this is aimed at the more advanced user, I have not commented the code, but I suspect you will easily find your way around it, as the concept is relatively simple.

'iLogic code by @ClintBrown3D, originally posted at https://clintbrown.co.uk/ilogic-suppress-unsuppress-and-delete-rules
On Error GoTo ClintsErrorTrap
doc = ThisApplication.ActiveDocument
Logic = iLogicVb.Automation
Dim ClintBrown3D As New ArrayList
Dim ListOrules As System.Collections.IEnumerable = Logic.Rules(doc)

UnofficialInventor = InputListBox("What would you like to do?", {"Suppress Rules","Unsuppress Rules", "Delete Rules"}, UnofficialInventor, Title := "@ClintBrown3D", ListName := "This Utility lets you Suppress/Unsuppress/Delete iLogic Rules")
	If UnofficialInventor = "Suppress Rules" Then : GoTo Suppress : End If
	If UnofficialInventor = "Unsuppress Rules" Then : GoTo Unsuppress : End If
	If UnofficialInventor = "Delete Rules" Then : GoTo Delete : End If
	If UnofficialInventor = "" Then : GoTo ClintsErrorTrap : End If

Suppress :
For Each oRule As iLogicRule In ListOrules
ClintBrown3D.Add(oRule.Name)
Next
	iLogicRules = InputListBox("Select A rule to suppress" , ClintBrown3D, UnofficialInventor, Title := "@ClintBrown3D: Suppress a Rule", ListName := "Below is a list of all internal rules in this document")
	iLogicVb.Automation.GetRule(doc, iLogicRules).IsActive = False
Return

Unsuppress :
For Each oRule As iLogicRule In ListOrules
ClintBrown3D.Add(oRule.Name)
Next
	iLogicRules1 = InputListBox("Select A rule to Unsuppress" , ClintBrown3D, UnofficialInventor, Title := "@ClintBrown3D", ListName := "Below is a list of all internal rules in this document")
	iLogicVb.Automation.GetRule(doc, iLogicRules1).IsActive = True
Return

Delete :
For Each oRule As iLogicRule In ListOrules
ClintBrown3D.Add(oRule.Name)
Next
	iLogicRules2 = InputListBox("Select A rule to Delete", ClintBrown3D, UnofficialInventor, Title := "@ClintBrown3D: Delete a Rule", ListName := "Below is a list of all internal rules in this document")
	
i = MessageBox.Show("Are you sure that you want to permanently Delete **" & iLogicRules2 & " **", "DELETE " & iLogicRules2 ,MessageBoxButtons.YesNo)
If i = vbYes Then : GoTo ClintBrown1 : Else : GoTo ClintsErrorTrap : End If

ClintBrown1 :
	iLogicVb.Automation.DeleteRule(doc, iLogicRules2)
	MessageBox.Show(iLogicRules2 & " Successfully Deleted" & vbNewLine & vbNewLine & "Hitting Undo may restore the rule", "@ClintBrown3D")
Return

ClintsErrorTrap :

I have also written a simpler version of the code that suppresses all iLogic Rules in the file. It also give the user the option to unsuppress all of the iLogic Rules in the file.

Here is an animated GIF of it in action:

autodesk inventor ilogic suppress rules

Below is the iLogic Code:

'iLogic code by @ClintBrown3D, originally posted at https://clintbrown.co.uk/ilogic-suppress-unsuppress-and-delete-rules
On Error GoTo ClintsErrorTrap
doc = ThisApplication.ActiveDocument
Logic = iLogicVb.Automation
Dim ListOrules As System.Collections.IEnumerable = Logic.Rules(doc)

UnofficialInventor = InputListBox("What would you like to do?", {"Suppress ALL Rules","Unsuppress ALL Rules"}, UnofficialInventor, Title := "@ClintBrown3D", ListName := "This Utility lets you Suppress/Unsuppress iLogic Rules")
	If UnofficialInventor = "Suppress ALL Rules" Then : GoTo Suppress : End If
	If UnofficialInventor = "Unsuppress ALL Rules" Then : GoTo Unsuppress : End If
	If UnofficialInventor = "" Then : GoTo ClintsErrorTrap : End If

Suppress:
For Each oRule As iLogicRule In ListOrules
iLogicVb.Automation.GetRule(doc, oRule.Name).IsActive = False
Next
Return

Unsuppress:
For Each oRule As iLogicRule In ListOrules
iLogicVb.Automation.GetRule(doc, oRule.Name).IsActive = True
Next
Return

ClintsErrorTrap :

These versions of the code (both utilities) were briefly tested with Inventor 2020.

Please note that I cannot offer any additional support, this blog post is offered as-is, and is aimed at the more advanced user.

As always, please test all iLogic code extensively on non-production files. Do not use any code in a production environment until YOU have thoroughly tested it and have verified that it works as expected. Always back up any data before running any experimental code. You are ultimately responsible for any iLogic code that you run, so make sure you test it thoroughly!

This site takes absolutely no responsibility for how you use this code in production (see disclaimer).