Pass parameters to an iLogic Rule

<?xml encoding=”UTF-8″>By Adam Nagy

In this article we are accessing iLogic Rules from outside and run them using RunRule(“componentName”, “ruleName”), which does not provide arguments to pass extra information to the Rule. There are other functions though that can be used. They are listed on this help page. In case it moves somewhere else I copy here the info:

Rule arguments

iLogic provides advanced functionality that allows you to pass context information as rule arguments into the rules you run. This information can be used to modify the behavior of a rule without having to create a duplicate rule.

You pass rule arguments using functions available in the IiLogicAutomation interface (for external clients), and in iLogicVB (for other rule code and internal clients). These arguments are made available within a rule via the RuleArguments property.

For IiLogicAutomation, the functions available include:

Function <strong>RunRuleWithArguments</strong>(
ByVal doc As Inventor.Document,
ByVal ruleName As String,
ByVal ruleArguments As Inventor.NameValueMap) As Integer
Function <strong>RunExternalRuleWithArguments</strong>(
ByVal doc As Inventor.Document, ByVal ruleName As String,
ByVal ruleArguments As Inventor.NameValueMap) As Integer
Function <strong>RunRuleDirectWithArguments</strong>(
ByVal rule As iLogicRule,
ByVal ruleArguments As Inventor.NameValueMap) As Integer

For iLogicVB, the functions available include:

Function <strong>RunRule</strong>(
ByVal ruleName As String,
ByVal ruleArguments As Inventor.NameValueMap) As Integer
Function <strong>RunRule</strong>(
ByVal compoOrDocName As Object, ByVal ruleName As String,
ByVal ruleArguments As Inventor.NameValueMap) As Integer
Function <strong>RunExternalRule</strong>(
ByVal ruleName As String,
ByVal ruleArguments As Inventor.NameValueMap) As Integer

Create rule arguments

To create rule arguments, use the Inventor API to create a new NameValueMap object. It is then passed to one of the functions when running the rule.

Access an argument passed to the rule

x = RuleArguments("myArg")

Determine if an argument has been passed to the rule

If RuleArguments.Exists("myArg") Then...

Pass the set of arguments to another rule using RunRule

iLogicVB.RunRule("someOtherRule", RuleArguments.Arguments)

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading