How trigger only rules which are using user parameters ?

How trigger only rules which are using user parameters ?

basile.sciaudeau
Contributor Contributor
1,867 Views
8 Replies
Message 1 of 9

How trigger only rules which are using user parameters ?

basile.sciaudeau
Contributor
Contributor

Hello Inventor Community,

 

Today, I ask your help for problem about ilogic rules running. I want to configure components with ilogic rules and parameters in a loop. My problem is, when I want to import parameter into my component, the rule is triggered and make the changes I want but sometimes, a parameter I wanted to write is replace by the result of another rule execution. To tried to solve it this is my process :

  1. Disable all ilogic rules of a component using the attribute "AutomaticOnParamChange" of "iLogicRule" class.
  2. From an SQL database, apply value of all ilogic parameters I need to with the command "Parameter("my_param") = xxx"
  3. Enable all rules which had the attribute "AutomaticOnParamChange=true" before the process.

The last step is to run all rules which are using parameters (read or write) and due to step 2, parameters are initialize and all works good.

 

So, to solve my problem, I have some other ideas but I didn't found the solution on Inventor/Ilogic API Documentation :

  • Trigger the rules by parameters writing, even if the parameter value don't change
  • For each user parameter, get the list of rules which read or write this parameter (ilogic editor can highlight params in blue)
  • Get XML structure of ilogic Form into a document.

 

Do you have an idea of how can I implement one of the solution above ?

 

Thanks in advance for your time.

B. Sciaudeau

0 Likes
Accepted solutions (1)
1,868 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Hi @basile.sciaudeau.  How are your rules currently being triggered to run?  Do you have one (or more) of your rules listed under one (or more) of the events in the Event Triggers dialog?  Are they just being triggered to run because they are 'local' rules (saved within the document), and you are using the unquoted names of parameters within them?  If you do not want the rule to be triggered to run every time the value of a parameter changes, you will need to either remove the rule from the "Any Model Parameter Change" event or the "Any User Parameter Change" event in the Event Triggers dialog...or change how you are using those parameter names within the rules.  You can change an unquoted parameter name to 'Parameter("ParameterName")' and it will work the way as before, but will then not trigger the rule to run every time the value of that parameter changes.  There are also other, more complicated ways to respond to parameter change events which would give you more control, such as creating your own event handler codes.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 9

basile.sciaudeau
Contributor
Contributor

Hi @WCrihfield,

 

Thank you for your answer. About my rules, they are triggered when a param change with unquoted parameter name. I want to continue to run rules when parameter change but when I want to write some parameters in one shot, I need to disable rules temporarely to be sure that my parameters will not be replace. The writing process is done by external rule which control user parameters of a document.

 

Is it possible to trigger the rule even if the written parameter value is the same as before ?

0 Likes
Message 4 of 9

WCrihfield
Mentor
Mentor

No. I do not believe that is possible.  I tried it all 3 ways mentioned above, and got no response when the actual value was not changed, no matter how it was done.  Also tried it with a text type user parameter.  Same results.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 9

basile.sciaudeau
Contributor
Contributor
Ok thank you. And do you know if an attribute or a method exist to get all read/write parameters of a iLogicRule object ?
0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor
Accepted solution

I know how to get all the text within an iLogic rule, but not really how to recognize if each word might be the name of a local parameter.  I suppose you could check each word within the rule's text agains the names of each of the parameter of the document it is supposed to be targeting, but that could be a lot of processing and likely result in a lot of 'false positives'.

I do know of a trick you may be able to use in your external rule though.  You can toggle the 'DelayedRuleRunningMode' (Link1, Link2, Link3) to active when you don't want any rules to react to parameter changes for a while, then exit that mode when done with it.  This bit of code below will toggle that setting...just for reference.

 

If iLogicVb.Automation.InDelayedRuleRunningMode Then
	iLogicVb.Automation.ExitDelayedRuleRunningMode
Else
	iLogicVb.Automation.EnterDelayedRuleRunningMode
End If

 

 

P.S.:  There is also the iLogicVb.Automation.RulesEnabled (Boolean) and the  iLogicVb.Automation.RulesOnEventsEnabled (Boolean)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 9

basile.sciaudeau
Contributor
Contributor

Ok thank you. I will try your solution with my rules. Do you know if it's possible to use iLogicVb.Automation delayed mode for specific document ?

 

Just one more thing, do you know if it's possible to access to form definition inside a document. I have already access to external ilogic form in my workspace folder (.xml files). It will be great if I could access to the form into document because I could make the distinction between rules that contains parameters or not, then run it if it's necessary.

Here is an example of internal rules in a document. Some of these rules have the parameter "Don’t Run Automatically" checked because they have no parameters linked.

 

2022-05-17 08_23_02-Window.png

 

0 Likes
Message 8 of 9

basile.sciaudeau
Contributor
Contributor
Thank you very much for the solution above, this solve my problem !

Have a good day !!
0 Likes
Message 9 of 9

WCrihfield
Mentor
Mentor

Hi @basile.sciaudeau.  Glad to hear that I was able to help you out.

In 'Message 7' of this post you asked about setting for delayed mode for individual rules.  You mentioned one of the settings in your first post message for turning off 'AutomaticOnParamChange', but there are a couple other similar settings available for each rule too ('FireDependentImmediately' & 'IsActive').  Setting 'IsActive' property to False is basically the same as right clicking on the rule and choosing 'Suppress Rule', or clicking to check the option box within the rule's options called 'Suppressed'.  When the rule is suppressed, it obviously will not run at all.  Setting the 'FireDependentImmediately' property to False appears to be a way to force a rule to finish completely before any other rules run that may be triggered to run by stuff that happens within the rule, then any other rules that may have been triggered to run can do so when it finishes.  To me, this doesn't sound exactly like what you were wanting though.

Here is another sample if some fairly simple iLogic code for gathering & filtering a bunch of local rules within a document, then only doing stuff with some of them.

oDoc = ThisDoc.Document 'specify document containing the rules
oAuto = iLogicVb.Automation
oAllRules = oAuto.Rules(oDoc)
Dim oRulesToControl As New List(Of iLogicRule)
Dim oOtherRules As New List(Of iLogicRule)
Dim oRule As iLogicRule = Nothing
For Each oRule In oAllRules
	If oRule.Name.StartsWith("Lien vers") Or _
		oRule.Name = "iTrigger" Then
		oOtherRules.Add(oRule)
	Else
		oRulesToControl.Add(oRule)
	End If
Next
oRule = Nothing
MsgBox("oOtherRules.Count = " & oOtherRules.Count, , "")
MsgBox("oRulesToControl.Count = " & oRulesToControl.Count,,"")
'For Each oRule In oRulesToControl
'	'oRule.AutomaticOnParamChange = False
'	'oRule.FireDependentImmediately = False
'	oRule.IsActive = False 'Suppress the rule
'Next

'do some stuff here with other code or run other rule(s)

'For Each oRule In oRulesToControl
'	'oRule.AutomaticOnParamChange = True
'	'oRule.FireDependentImmediately = True
'	oRule.IsActive = True 'un-suppress the rule
'Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)