Determine How iLogic is Being Called

Determine How iLogic is Being Called

Matthew_Policelli
Advocate Advocate
290 Views
3 Replies
Message 1 of 4

Determine How iLogic is Being Called

Matthew_Policelli
Advocate
Advocate

Is there a way to determine if an iLogic rule is being called through a form or through an event trigger, and prompt the user for confirmation ONLY when it is being called by an event trigger?

 

The rule in question creates a PDF. If the user is pressing a button on a form to run the rule, I'd like it to just create the PDF no questions asked. However, if the rule is running because of an event trigger, I would like it to ask the user if they want to create the PDF or not.

0 Likes
Accepted solutions (1)
291 Views
3 Replies
Replies (3)
Message 2 of 4

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Matthew_Policelli 

 

You will need 2 rules.

 

Let's call them :

  1. PDF Button Rule
  2. PDF Rule

On the form, use the rule called "PDF Button Rule" as the button.

The event trigger still calls the original rule (  "PDF Rule" in this example ) 

 

The code for "PDF Button Rule" will call the "PDF Rule" and send it an argument to tell it to ask questions or not ask questions, and would be something like this:

 

Dim oValueMap As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
oValueMap.Add("SkipPrompt", True)
iLogicVb.RunRule("PDF Rule", oValueMap)

 

 

The PDF Rule would have some code at the beginning to receive the argument from the other rule, and use it to determine if it needs to prompt the user. It would look something like this:

 

'set default value for variable 
oSkipPrompt = False
'try to set variable based on argument from other rule
oSkipPrompt = RuleArguments("SkipPrompt")

If oSkipPrompt = False Then 
	oInput = MessageBox.Show("Are you sure you want to create the PDF?", "iLogic",MessageBoxButtons.YesNo)
	If oInput = vbNo Then Exit Sub 
End If

''' code to create PDF here
''' code to create PDF here...
 MessageBox.Show("your PDF was created!", "iLogic")

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

0 Likes
Message 3 of 4

Matthew_Policelli
Advocate
Advocate

I'm accepting this as an answer. Also, this led me down the rabbit hole of learning about RuleArguments and SharedVariables, which I previously didn't know were a thing!

 

One last question I have is this: Your answer used RuleArguments, but would creating a SharedVariable, running the rule, and then deleting the SharedVariable work just as well? Is there a reason to use one over the other?

0 Likes
Message 4 of 4

Curtis_Waguespack
Consultant
Consultant

Hi @Matthew_Policelli 

 

I think ShareVariables are useful when we want to create/set a variable in Rule 1 and have Rule 2, 3, 4 and 5 use that value, and maybe even update that value along the way.

 

The form & event trigger scenario is a bit more simple, but indeed you could use a ShareVariable for that scenario as well. 

 

I tend to use rule arguments when I am handing a value to a rule, as a single action. If I want that value to persist in memory, so that another rule "might" use, I use a shared variable. That is just my thought on it though, I don't think there are any strict rules as to when to use on or the other.

EESignature

0 Likes