Re-run a rule

Re-run a rule

blandb
Mentor Mentor
533 Views
7 Replies
Message 1 of 8

Re-run a rule

blandb
Mentor
Mentor

I have a very simple rule that chooses 3 names, and then when the name is selected, it will run their own rule showing their name. Once the name has been shown it prompts to run the rule again, basically to call up the first rule to choose a name again and just repeat the process. But, the rule will not run again once I choose "yes"

 

rule 1:

d0 = InputListBox("choose 1", MultiValue.List("d0"), d0, Title := "Title", ListName := "List")

Select Case d0
Case "bob"
	iLogicVb.RunRule("bob")
Case "frank"
	iLogicVb.RunRule("frank")
Case "tom"
	iLogicVb.RunRule("tom")
End Select

 

bob's rule:

MessageBox.Show("this is bob", "message title")
answer = MessageBox.Show("you want to run this again?", "Message Title",MessageBoxButtons.YesNo)
If answer = vbYes Then
	iLogicVb.RunRule("rule 1")
End If	

Here is where rule 1 will not fire again and start the process over, what is wrong?

Autodesk Certified Professional
0 Likes
Accepted solutions (1)
534 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @blandb.  Since Rule 1 is changing the value of a blue, unquoted, iLogic parameter, it will need the familiar:

RuleParametersOutput()

...line of code after the line of code changing its value, to immediately update the model to the changed value, before moving forward with other code that will rely on that changed value.  That is the 'update' line that is specifically for those types of parameters, and not really used for anything else.  Try adding that into that rule, and see if that helps.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

blandb
Mentor
Mentor

Thanks for the reply, so you are saying after the d0=.... line, enter what you mentioned?

 

I have never used that line before. This is just a simplified version of the actual problem, so I was just wanting to see if I could get this loop going as needed.

Autodesk Certified Professional
0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Yes, in Rule 1, on the next line after your [d0 = ...] line of code, which sets the value of the d0 parameter, use that line of code I posted.

 

It is a bit difficult to explain, but there is a whole other Class block of code that seems to get auto-generated for our iLogic rules, which we never see.  This is because the default Class named 'ThisRule' is a 'Partial' Class, and the hidden half seems like it may even be a bit dynamic, meaning depending on what we include in our regular rule, its contents may get changed to match the need.  I believe this is partially to support what they call 'Rule Objects', which seem like variables that have already been assigned values, and usually represent some sort of Interface type object.

 

If you have ever looked at the text file that gets automatically created when we run an iLogic rule, within the [C:\Users\%user%\AppData\Local\Temp\iLogic Rules\ folder, you will notice some extra code in them that you did not include in your rule.  And because of this, sometimes when you see an error message, and pay close attention to it, you may notice it mention a line number where the problem was encountered do not seem to match up with your expectation.  It is because it is looking at that other version of the code.  That temp file still does not include that whole other partial Class block of code, but it does include the hints about it, because it will automatically create that default 'ThisRule' Class, and enclose our regular code within it, if we did not create that Class ourselves, within our own code.  It seems like there may be 3 versions of our rules...the portion that we write, the slightly altered version, like what we see in the temp file, then the whole rule that includes the other half of the 'ThisRule' Class block of code.  Well, that line of code I showed you is for a special Sub routine that is defined within the other/hidden half of the 'ThisRule' Class block of code, and it is specifically for pushing the current values of those special, blue, 'iLogic parameters' to the model.  And it only happens at the line of code where it is called to run.  So, if you have a long rule with lots of progressive interactions with those special, blue, iLogic parameters, then you may need to use that special line of code in more than one place, depending on the situation, and how critical the changes / updates are to further code after that point.  Other ways of interacting with Parameters do not seem to have anything to do with that special Sub routine.  It is just something that help support their functionality within 'internal' iLogic rules.

 

You can also see this special line of code mentioned in the following online help documentation page, where it is talking about the standard iLogic Snippets for working with Parameters:

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-6B4885C8-7E75-4FEA-8DEF-EA7D40F33EB3 

...near the bottom of that page.

WCrihfield_0-1738000335272.png

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

blandb
Mentor
Mentor

Thanks, but I add that and nothing seems to change.

Autodesk Certified Professional
0 Likes
Message 6 of 8

WCrihfield
Mentor
Mentor

Fair enough.  That must not be the main problem here then.

Next theory...

When 'rule 1' calls 'rule 2' to run, then rule 1 will be essentially 'paused', waiting for rule 2 to finish its task, then control will return to rule 1.  However, if rule 2 is also calling rule 1 to run before it ends, this must be causing an odd (or impossible) situation, because that rule is already active and waiting for control to return to it, but is being called to run again before that point.

 

There was another very similar case recently where someone was using launching an iLogic Form, then using a button within that Form to run an external iLogic rule, and near the end of that external rule, they had some code to close all iLogic Forms, but that was not working for them.  I tested that scenario myself, and it worked just fine for me, but not for them.  This seemed like another case of the primary item calling a secondary item, then waiting on the secondary item to finish, but the secondary item trying to control the primary item.  Apparently that's a tricky chain of events for Inventor to manage properly.  So, this may be an issue that is a bit buggy in some versions of Inventor...not sure.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 8

mat_hijs
Collaborator
Collaborator
Accepted solution

After Bob's rule is ran it will continue running your main rule. Your prompt should be at the end of your main rule and then you can use GoTo to go back to the start of the rule. I think this is what you're after.

 

Main rule:

Start:
Name = InputListBox("choose 1", MultiValue.List("Name"), Name, Title := "Title", ListName := "List")

Select Case Name
Case "Bob"
	iLogicVb.RunRule("Bob's Rule")
Case "Frank"
	iLogicVb.RunRule("Frank's Rule")
Case "Tom"
	iLogicVb.RunRule("Tom's Rule")
End Select

If MsgBox("Run another Rule?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then GoTo Start

 

 Bob's, Frank's and Tom's rules:

MsgBox(iLogicVb.RuleName & " is running.", MsgBoxStyle.OkOnly)

 

0 Likes
Message 8 of 8

blandb
Mentor
Mentor

I have never used the goto before, it worked. Thanks.

Autodesk Certified Professional
0 Likes