iLogic – Run Rules From a List

@ClintBrown3D Autodesk Inventor blog ilogic run rules from list

I’ve written an iLogic rule that gathers the names of all of the internal rules in a file, and then shows them on an input list box. The user can run any rule on the list by clicking on the rule in the list.

This could be quite useful for users, as it could pop up on an event trigger when a file is opened, or saved.

Here is a GIF of the rule in action.

 

Unofficial Inventor blog ilogic run rules from list
click me for a high res version

 

Below is the iLogic code.

'iLogic Rule by @ClintBrown3D
'Originally posted here: https://clintbrown.co.uk/ilogic-run-rules-from-a-list

On Error GoTo ClintsErrorTrap
doc = ThisApplication.ActiveDocument
Logic = iLogicVb.Automation
Dim ClintBrown3D As New ArrayList
Dim ListOrules As System.Collections.IEnumerable = Logic.Rules(doc)

For Each oRule As iLogicRule In ListOrules
ClintBrown3D.Add(oRule.Name)
Next
	iLogicRules = InputListBox("Select A rule to run" , ClintBrown3D, iLogicRules, Title := "Unofficial Inventor", ListName := "Below is a list of all internal rules in this document")
	iLogicVb.RunRule(iLogicRules)

Return
ClintsErrorTrap :
MessageBox.Show("Nothing seleted!", "@ClintBrown3D", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)

This version of the code was tested with Inventor 2020. The rule only works with internal rules.

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!