How to select case between iLogic rules

How to select case between iLogic rules

Anonymous
Not applicable
3,366 Views
7 Replies
Message 1 of 8

How to select case between iLogic rules

Anonymous
Not applicable

Hi,

 

I have an assembly model in inventor 2022 with 6 iLogic Rules in it. I have a user parameter of Case 1 and Case 2 and I want my model to be built based on the first 3 iLogic rules if users select "Case 1" and my model to be built based on the second 3 iLogic rules if users select "Case 2". I want to be able to do this for 3 or 4 cases as well if it's needed later. 

 

I wonder if that is possible!?

0 Likes
Accepted solutions (1)
3,367 Views
7 Replies
Replies (7)
Message 2 of 8

Ralf_Krieg
Advisor
Advisor

Hello

 

You could try a rule wich coordinates all your rules with a select case statement.

Activate the "Don't run automatic" option in all other rules and remove them from any trigger event if assigned to.

Select Case Parameter.Param("Case")
	Case "Case1" :	iLogicVb.RunRule("ruleName1")
				iLogicVb.RunRule("ruleName2")
				iLogicVb.RunRule("ruleName3")
	Case "Case2" :	iLogicVb.RunRule("ruleName4")
				iLogicVb.RunRule("ruleName5")
				iLogicVb.RunRule("ruleName6")
	Case "Case3" :	iLogicVb.RunRule("ruleName7")
				iLogicVb.RunRule("ruleName8")
				iLogicVb.RunRule("ruleName9")
	Case Else : 'optional
				iLogicVb.RunRule("ruleName1")
				iLogicVb.RunRule("ruleName4")
				iLogicVb.RunRule("ruleName7")
	End Select
	

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks for the response. 

I tried that but it's not working. I cannot understand where in that code I link the number of case (e.i. 1, 2 or 3) from the user parameter to the ilogic rule.

 

 

0 Likes
Message 4 of 8

Ralf_Krieg
Advisor
Advisor

Hello

 

Step-by-Step

- Create a new rule and insert the code below

- Create a numeric, unitless, multivalue user parameter "Cases" in your assembly wit values 1, 2, 3 and 4

- Create a sketch in your assembly

- Draw a line

- Set a linear dimension to this line and in the dimension edit filed insert "Cases * 1mm"

- Exit sketch and make it invisible

- Open iLogic event trigger dialog and drop your rule to the "model parameter change" option

- Go to fx-parameter and change the value of parameter "Cases". A message will appear showing the selected case.

 

Select Case Parameter.Param("Cases").Value 
	Case 1 : 
				MsgBox("Case 1 selected")
'				iLogicVb.RunRule("ruleName1")
'				iLogicVb.RunRule("ruleName2")
'				iLogicVb.RunRule("ruleName3")
	Case 2 :
				MsgBox("Case 2 selected")
'				iLogicVb.RunRule("ruleName4")
'				iLogicVb.RunRule("ruleName5")
'				iLogicVb.RunRule("ruleName6")
	Case 3 :
				MsgBox("Case 3 selected")
'				iLogicVb.RunRule("ruleName7")
'				iLogicVb.RunRule("ruleName8")
'				iLogicVb.RunRule("ruleName9")
	Case 4 : 
				MsgBox("Case 4 selected")
				'optional
'				iLogicVb.RunRule("ruleName1")
'				iLogicVb.RunRule("ruleName4")
'				iLogicVb.RunRule("ruleName7")
End Select

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 5 of 8

Ralf_Krieg
Advisor
Advisor

Or an alternative way:

- Create a new rule and insert the code below

- Create a multivalue text user parameter "Cases" and add values "Case 1", "Case 2", "Case 3" and "Case 4".

- Go to fx-parameter and change the value of parameter "Cases". A message will appear showing the selected case.

 

Select Case Cases
	Case "Case 1" : 
				MsgBox("Case 1 selected")
'				iLogicVb.RunRule("ruleName1")
'				iLogicVb.RunRule("ruleName2")
'				iLogicVb.RunRule("ruleName3")
	Case "Case 2" :
				MsgBox("Case 2 selected")
'				iLogicVb.RunRule("ruleName4")
'				iLogicVb.RunRule("ruleName5")
'				iLogicVb.RunRule("ruleName6")
	Case "Case 3" :
				MsgBox("Case 3 selected")
'				iLogicVb.RunRule("ruleName7")
'				iLogicVb.RunRule("ruleName8")
'				iLogicVb.RunRule("ruleName9")
	Case "Case 4" : 
				MsgBox("Case 4 selected")
				'optional
'				iLogicVb.RunRule("ruleName1")
'				iLogicVb.RunRule("ruleName4")
'				iLogicVb.RunRule("ruleName7")
End Select

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 8

J-Camper
Advisor
Advisor

I'm guessing these are all local rules, but I'm not sure what type of User Parameter Your case selection is or how you plan on trigger all the rules.   Another way would be to add a line at the beginning of each rule that cancels the rule if the Parameter value doesn't match.  Something like this:

If Parameter("Case") <> "Case 1" Then Exit Sub 'If the Text Parameter "Case" does not equal "Case 1", then the rule will terminate

The sample above assumes the User Parameter is a Text Parameter. 

 

Let me know if you have any questions

0 Likes
Message 7 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous 

 

Attached is a quick working example (inv 2020 file) using the examples posted earlier.

 

The form triggers a rule called Case Rule, and that rule runs a set of rules depending upon the selected case (color).. and each rule displays a message box with the rule name.

 

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

EESignature

0 Likes
Message 8 of 8

Anonymous
Not applicable
Accepted solution

Thanks. I used that code but for some reason it was running 3 of the rules correctly but not reading one of them correctly (I had 4 rules for each case)

 

So I figured out another way to make it work. I used If statement, suppressing some tules and run the rest for that condition. 

 

The code that I used in case someone else had the same question as well. 

 

If d1 = 1 Then

auto = iLogicVb.Automation

auto.GetRule(ThisDoc.Document, "rule1").IsActive = False

auto.GetRule(ThisDoc.Document, "rule2").IsActive = False

auto.GetRule(ThisDoc.Document, "rule3").IsActive = False

auto.GetRule(ThisDoc.Document, "rule4").IsActive = False

iLogicVb.RunRule("rule5")

iLogicVb.RunRule("rule6")

iLogicVb.RunRule("rule7")

iLogicVb.RunRule("rule8")

 

ElseIf d1 = 2

.

.

.

End if

0 Likes