Setting parameter value to external rule from another rule

Setting parameter value to external rule from another rule

jfenter
Enthusiast Enthusiast
706 Views
2 Replies
Message 1 of 3

Setting parameter value to external rule from another rule

jfenter
Enthusiast
Enthusiast

I've been working with iLogic for about a year and have written a fair amount of code.  I feel like I've been doing it "the long way", relying almost solely on If...Then statements and Select...Case.  All of my code to this point has been written as internal rules, which obviously has it's drawbacks. 

I'm currently starting work on re-writing most of my coded parts with external rules so we can manage changes more efficiently.  In the effort to be more efficient, I'm starting to notice a LOT of redundant code that could be written as a separate rule then called out as needed.

But I'm lost.

I'd like to write a simple rule such as this:

''''RULE TO WARN ENTERED PART DIMENSION OVER/UNDER LIMIT''''

If partDimension > maxDimension Then
	partDimension = maxDimension

	MessageBox.Show("Enter Value Between " & minDim & " and " & maxDim & " mm.", "Maximum Limit Rule", MessageBoxButton.OK, MessageBoxIcon.Error)
ElseIf partDimension > minDimension Then
	partDimension = minDimension
	MessageBox.Show("Enter Value Between " & minDim & " and " & maxDim & " mm.", "Minimum Limit Rule", MessageBoxButton.OK, MessageBoxIcon.Error)
End If

This rule would set limits on width and length that are drawn from an excel spreadsheet.  This rule would be called on in a number of different places and the "partDimension" variable would be different in every situation (length, width, thickness, spacing between components, etc...).

 

 

My assumption is that I will be writing a second external rule that would set the desired variables, then run the rule given above with:

iLogicVb.RunExternalRule("ruleFileName")

How do I set the variables for the first rule in the secondary rules? 

 

0 Likes
707 Views
2 Replies
Replies (2)
Message 2 of 3

lmc.engineering
Advocate
Advocate

Hi @jfenter

Appreciate this is a month old, but figured no-one else was answering, so here goes: 

 

You could use shared variables for this. Something like:

 

SyntaxEditor Code Snippet

Sub Main()
'Call External Rule to return max and min:
iLogicVb.RunExternalRule("My Value Holding Rule")

maxDimension = SharedVariable("MaxDim")
minDimension = SharedVariable("MinDim")

If partDimension > maxDimension Then
	partDimension = maxDimension
	MessageBox.Show("Enter Value Between " & minDim & " and " & maxDim & " mm.", "Maximum Limit Rule", MessageBoxButton.OK, MessageBoxIcon.Error)
ElseIf partDimension > minDimension Then
	partDimension = minDimension
	MessageBox.Show("Enter Value Between " & minDim & " and " & maxDim & " mm.", "Minimum Limit Rule", MessageBoxButton.OK, MessageBoxIcon.Error)
End If
'Reset Shared Variables
SharedVariable("MaxDim") = Nothing
SharedVariable("MinDim") = Nothing
End Sub

Where the holding Rule will contain the excel link, and apply the shared variable values:

 

SyntaxEditor Code Snippet

Sub Main()
	'Call excel to populate shared variables
	SharedVariable("MaxDim") = 500
	SharedVariable("MinDim") = 100
End Sub

 

This would be good for you if you only need to pass information one way, however, if you need to pass info both ways and run further conditional arguments, you'd be better looking at Rule arguments. For example:

This is your calling rule, located in your part file (or as an external rule if you wish)

SyntaxEditor Code Snippet

	'---Set up arguments'---
Dim oRuleArguments As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
oRuleArguments.Add("PartNumber",sPartNumber)
oRuleArguments.Add("PartName",sPartName)

'---Call external "function" rule---
iLogicVb.RunExternalRule("Find My Values",oRuleArguments)
'---Retrieve resultant value from external rule---
sSomeInformation = oRuleArguments.Item("ReturnedValue")

 Then your function rule (Main number cruncher) will look something like this:

 

SyntaxEditor Code Snippet

'Retrieve info from calling rule
arg1Value = RuleArguments("PartNumber")
arg2Value = RuleArguments("PartName")
'Do some stuff
'Call Excel etc..
	'code
'Assign value to return to calling rule
RuleArguments.Arguments.Value("ReturnedValue") = SomethingGood 

Hope this helps

 

Regards

Message 3 of 3

jfenter
Enthusiast
Enthusiast

I thought shared variables might be involved but I couldn't find good examples on how to implement them into my code to make them work properly.  I've moved on from this project for the time being, but I will test your answer when I get back to it soon.  Thanks!