How to loop through, and run all rules that exist in an assembly via iLogic

How to loop through, and run all rules that exist in an assembly via iLogic

ABoaro
Enthusiast Enthusiast
1,082 Views
6 Replies
Message 1 of 7

How to loop through, and run all rules that exist in an assembly via iLogic

ABoaro
Enthusiast
Enthusiast

I am aware of the feature to right click in the Rules browser under 'iLogic' to run all rules. However, I am wondering how that can be done with iLogic rules. Currently, I can only see writing a rule that has a line 'iLogicVb.RunRule("Rule Name")' for every rule as the solution.

 

This would be very cumbersome to manage if rules get deleted or added down the road to the template that contains these rules. I want to know how a loop can be written to run every rule that exists in the Rules Tab in the iLogic browser.


Any help would be much appreciated.

0 Likes
Accepted solutions (2)
1,083 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Here is a quick and simple example you can use:

Dim oDoc As Document = ThisDoc.Document
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Dim oRules As IEnumerable = oAuto.Rules(oDoc)
Dim oRule As iLogicRule
For Each oRule In oRules
	oAuto.RunRuleDirect(oRule)
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

ganesh_omkaar
Contributor
Contributor

Where should it write in vb or ilogic

0 Likes
Message 4 of 7

J-Camper
Advisor
Advisor
Accepted solution

There is not a command for "RunAllRules" but there is a command for "RegenerateAllRules".  See if this is enough for you:

Dim reGen As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("iLogic.RegenAllRules")
reGen.Execute
Message 5 of 7

ABoaro
Enthusiast
Enthusiast

I have never used the Regenerate Rules feature before. Is there a benefit from regenerating rules as opposed to looping through and running rules? Your method works for all intents and purpose the same as the one mentioned above. The difference it appears is that the regenerate only does rules that are not suppressed. Is there any advantage in that? 

0 Likes
Message 6 of 7

J-Camper
Advisor
Advisor

I don't know the difference between RunAllRules and RegenerateAllRules.  Inventor Help - work with rules in iLogic stes this about RegenerateAllRules: "This command reconnects the rule to Inventor parameters, recompiles the rule, and then runs it."

 

I don't think run all rules will run suppressed rules either, at least i think it should leave them alone.

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

Here's the slightly modified code that checks if the Rule 'IsActive' (not suppressed) or not.

Dim oDoc As Document = ThisDoc.Document
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Dim oRules As IEnumerable = oAuto.Rules(oDoc)
Dim oRule As iLogicRule
For Each oRule In oRules
	If oRule.IsActive Then oAuto.RunRuleDirect(oRule)
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes