Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Run part of a rule from Form Button

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
Brian.Price
1264 Views, 11 Replies

Run part of a rule from Form Button

I currently have a rule and form attached to it that I set the parameters to provide the rule instructions on which sub the rule needs to run when I click the form rule button. Is there a way to have a button only run one of the subs, or do I need to have a rule for each button?

These are simple tasks like reorganizing the parts list, adding center lines etc. 

I have access in the form to do this but I have to double check the settings to make sure I don't change something by mistake. Having a one click button would eliminate the time to choose the inputs and chance of choosing incorrectly.

 

It' also nice to leave the parameters set for process flow so I don't have to change back and forth a lot from one page to the next.

11 REPLIES 11
Message 2 of 12

Hi @Brian.Price 

 

I'm not sure I follow all of what you're asking/saying, but here's one method.

 

Also just as an FYI  programming questions of this type are better asked on the Inventor Customization forum :
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

Set up a main rule with the subs

Sub Main
	oWhatToRun = RuleArguments("Action")

	If oWhatToRun = "Sub1" Then
		Call Sub1
	Else If oWhatToRun = "Sub2" Then
		Call Sub2
	Else If oWhatToRun = "Both" Then
		Call Sub1
		Call Sub2
	End If
End Sub


Sub Sub1

MessageBox.Show("Sub1", "ilogic")

End Sub

Sub Sub2

MessageBox.Show("Sub2", "ilogic")

End Sub

Then set up "button" rules that run the main rule with an argument that is used to choose which sub to run:

Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
map.Add("Action", "Sub1")
iLogicVb.RunRule("Rule 001", map)
Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
map.Add("Action", "Sub2")
iLogicVb.RunRule("Rule 001", map)
Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
map.Add("Action", "Both")
iLogicVb.RunRule("Rule 001", map)

 

 

aaa.png

 

bbb.PNG

 

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

Message 3 of 12

Thanks for the help but I think there is come confusion on my part.

I have a long rule with multiple subs in it. 

I would like a form button that runs one of those subs simply by clicking it.

Similar to if you just add the rule to the form it will run that rule.

 

This way I don't have several rules and only one that does what I need.

 

Perhaps it would be better to have multiple rules with a button for each.

This is my current form

1.JPG2.JPG

 

 

The first one is the settings to run the rule, the second is a button for each simple task rule that I have.

 

The button "Punch it Chewie" executes the main rule.

Message 4 of 12

Hi @Brian.Price 

 

If you don't want to break the rule up, I think you could easily use the approach I laid out earlier, which was to set up rules to be used as buttons, to send an argument to the main rule which tells it which sub or subs to run...

 

....but in looking at the list of tasks you have in your buttons I would actually have those tasks as separate rules (which can be a benefit for debugging, etc. ) and then I would have the "Punch it Chewie" rule use the RunRule or RunExternal rule line to call the rules in the order you prefer, this should give you the best of both worlds.

 

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

 

 

this would be the "Punch it Chewie" rule

'run internal rules
iLogicVb.RunRule("Replace Centerlines")
iLogicVb.RunRule("Export Drawings")
iLogicVb.RunRule("PDF")
'etc...
'or use this if the rules are external
iLogicVb.RunExternalRule("Replace Centerlines")
iLogicVb.RunExternalRule("Export Drawings")
iLogicVb.RunExternalRule("PDF")
'etc...

 

Message 5 of 12

Ok I think I get it now. Any way I look at it there will be a rule to use the button.

Message 6 of 12

@Curtis_Waguespack Any reason the line 

oWhatToRun = RuleArguments("Action")

would result in the error "'RuleArguments' is not declared. It may be inaccessible due to its protection level"? 

Message 7 of 12

Hi @eric.frissell26WKQ ,

 

It looks like my post above was kind of laid out backwards in the past, but hopefully this provides some clarity.

 

That is the 2nd part of the rule arguments use case.

 

This rule, called "Rule Sub1" calls up another rule called Rule 001, and provides an argument that tells it which sub routine within Rule 001 to run. So this is saying "run Rule 001, subroutine Sub1"

Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
map.Add("Action", "Sub1")
iLogicVb.RunRule("Rule 001", map)

 

This is Rule 001

Sub Main
	oWhatToRun = RuleArguments("Action")

	If oWhatToRun = "Sub1" Then
		Call Sub1
	Else If oWhatToRun = "Sub2" Then
		Call Sub2
	Else If oWhatToRun = "Both" Then
		Call Sub1
		Call Sub2
	End If
End Sub


Sub Sub1

MessageBox.Show("Sub1", "ilogic")

End Sub

Sub Sub2

MessageBox.Show("Sub2", "ilogic")

End Sub

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

Message 8 of 12

Ah, that makes sense!  The rule creating the argument needed to be created before the rule that the argument is being passed too... Thanks!  Pretty familiar with VBA but first iLogic rule... 

 

Question then.  I created the "Sub1" rule which will inevitably pass "action" to Rule 001 so is it possible to run Rule 001 directly (i.e. will it retrieve the argument from Sub1 without Sub1 being ran), or do you need to run Sub1 to pass the argument?

Message 9 of 12

Hi @eric.frissell26WKQ 

 

Good question.

 

Yeah, in this case the goal was to have 3 buttons to run the main rule, in different ways. So that is why the example is creating the other rules and passing arguments, simply to provide a button on the user form.

 

But we could get the user input via a message box and keep it all in the same rule, such as this:

 

Sub Main
	
	Dim oList = New String() {"Sub1", "Sub2", "Both" }
	
	oWhatToRun = InputListBox("Select what to run", oList, oList(2), "ilogic", "List")

	If oWhatToRun = "Sub1" Then
		Call Sub1
	Else If oWhatToRun = "Sub2" Then
		Call Sub2
	Else If oWhatToRun = "Both" Then
		Call Sub1
		Call Sub2
	End If
End Sub

Sub Sub1

MessageBox.Show("Sub1", "ilogic")

End Sub

Sub Sub2

MessageBox.Show("Sub2", "ilogic")

End Sub

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

Message 10 of 12

 

and/or something like this, if we want to get the input in different ways:

 

Sub Main
	'get argument value from another rule
	oWhatToRun = RuleArguments("Action")

	'if value is empty then get user input
	If oWhatToRun = "" Then
		Dim oList = New String() {"Sub1", "Sub2", "Both" }
		oWhatToRun = InputListBox("Select what to run", oList, oList(2), "ilogic", "List")
	End If

	If oWhatToRun = "Sub1" Then
		Call Sub1
	ElseIf oWhatToRun = "Sub2" Then
		Call Sub2
	ElseIf oWhatToRun = "Both" Then
		Call Sub1
		Call Sub2
	End If
End Sub

Sub Sub1

	MessageBox.Show("Sub1", "ilogic")

End Sub

Sub Sub2

	MessageBox.Show("Sub2", "ilogic")

End Sub
Message 11 of 12

This looks like the perfect way to accomplish getting the ability to run the rule from the rule or externally from a form.  Quick question though regarding the code: These two lines

 

'get argument value from another rule
	oWhatToRun = RuleArguments("Action")

	'if value is empty then get user input
	If oWhatToRun = "" Then
		Dim oList = New String() {"Sub1", "Sub2", "Both" }
		oWhatToRun = InputListBox("Select what to run", oList, oList(2), "ilogic", "List")
	End If

 

 Will oWhatToRun return a null value which errors when calling "Action" later or does returning a null value result in an error?

 

Thought was rather than 

 

If oWhatToRun = "" Then

 

it could be replaced with the error function

 

'get argument value from another rule
	oWhatToRun = RuleArguments("Action")

	'if value is empty then get user input
	If Err Then
		Dim oList = New String() {"Sub1", "Sub2", "Both" }
		oWhatToRun = InputListBox("Select what to run", oList, oList(2), "ilogic", "List")
	End If

 

Not sure if that would make it any more robust or just accomplish the same thing slightly differently

Message 12 of 12

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report