How to write this as an external rule?

How to write this as an external rule?

n_thomasWJZ8L
Explorer Explorer
505 Views
5 Replies
Message 1 of 6

How to write this as an external rule?

n_thomasWJZ8L
Explorer
Explorer

I am brand new to iLogic and VB in general, I am trying to write an external rule that modifies one parameter based on the value of another parameter. I figured out how to write the code to do this in an internal rule but I'm unsure how to reference parameters from a specific model into an external rule. Here is what I've written for the internal rule: 

 

If (LG = 17.9375) Then
    FTR_POS = DISTANCE_4
End If

If (LG > 35.9375) Then
    FTR_POS = DISTANCE_9
End If

If (LG > 17.9375 And LG < 35.9375 Or LG = 35.9375) Then
FTR_POS = DISTANCE_6 End If
0 Likes
Accepted solutions (1)
506 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

Hi @n_thomasWJZ8L 

This help page here deals with parameters of occurrences within an assembly. You reference the occurrence name which allows the rule to find the right occurrence and effect the parameter. There is also a method that allows you to place a filepath in for the document reference which would give you a link to a document not in the assembly. As you have probably allready found out local parameters cannot be referenced in external rules. 

 

Ilogic API Parameter Function

Parameter("PartA:1", "d12") = 6.3

And for additional reading there is methods to drive and create parameters via the Inventor API. This is a step up from using the ilogic API but it has more power for extra customization.

 

Export iproperty from parameter

Create Parameters using vb.net

Create Parameter VBA Sample API Help

Parameter Object API Help

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 6

n_thomasWJZ8L
Explorer
Explorer

I don't entirely comprehend the extent of what you're saying unfortunately because I'm so new there's really so much that is outside the depth of my understanding but let me try and explain my situation a bit more as I think the way it was phrased is misleading.

I'm not trying to reference a parameter for a part that's in an assembly. My company created a form that allows us to create a set of standardized parts while only changing the features that differ between each. For this specific example I have a feature position that is based on the overall length of this part. So if the length is greater than 36 inches the distance for this feature from the end of the part needs to be 9 inches. In and of itself the simple code that I wrote in the original post works well as an internal rule for this. However my company doesn't like using internal rules because if I were to use that I would have to go to each part individually and add this code in, if something in the code breaks later I would have to make the fix in each individual variation. I want to find a way to make this an external rule so I can go through each part just run this rule and it would automatically make the change.

I think instead of referencing the file name is there a way I could grab the parameter based off an iProperty? I think the easiest way to differentiate all these files would be to use the part number rather than trying to go off the file name.

If you need more clarification let me know as I'm currently rushing typing this out.

0 Likes
Message 4 of 6

A.Acheson
Mentor
Mentor
Accepted solution

If you just want to run the rule on the file then when the file is open manually run this external rule. All I have done in this rule is to take the original parameter and use it within the parameter function. This then targets the document to the the current document open when the the rule is run. The update lines at the end update the parameters and the document. The first article linked earlier explains how the various update line works. 

If (Parameter("LG") = 17.9375) Then
    Parameter("FTR_POS") = Parameter("DISTANCE_4")
End If

If (Parameter("LG") > 35.9375) Then
    Parameter("FTR_POS") = Parameter("DISTANCE_9")
End If

If ((Parameter("LG")> 17.9375 And (Parameter("LG") < 35.9375 Or (Parameter("LG") = 35.9375) Then
Parameter("FTR_POS")= Parameter("DISTANCE_6") End If

RuleParametersOutput()
iLogicVb.UpdateWhenDone = True.

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 6

n_thomasWJZ8L
Explorer
Explorer

Well that should work perfectly thank you so much!

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Hi @n_thomasWJZ8L.  Just as an added bonus, if needed or desired, there is a way to maintain the automatic triggering of the rule to run every time one of those parameter values changes in that document.  You may already be aware of this, but when you include those blue, unquoted parameter names within an internal iLogic rule, that will cause that rule to get ran every time the value of one of those parameters changes.  But since we can not use those blue, unquoted parameter names within external iLogic rules that way, what I am describing below is sort of like a workaround process to maintain that auto run functionality while still having your main code in an external rule.

 

Use an internal iLogic rule within that document that only contains some 'dummy' variables that are set to those blue, unquoted parameter names, then use a line of code to run your external iLogic rule.  Sort of like the following:

oTrigger = LG
oTrigger = FTR_POS
oTrigger = DISTANCE_4
oTrigger = DISTANCE_6
oTrigger = DISTANCE_9
iLogicVb.Automation.RunExternalRule(ThisDoc.Document, "YourExternalRuleNameHere")

Then, every time the value of one of them changes, it will trigger this internal rule to run, which will run the external rule.  All the critical code is still in the external rule, so if it needs to change, it can be done in that one place.  This 'dummy' internal rule is just the 'middle man' for enabling the automatic 'triggering' functionality.  I use that little trick quite a bit.  The only time you might ever want/need to change anything in this internal rule is if you changed the name of the external rule.  If you rename the parameters in this document, then this internal iLogic rule should update its blue parameter names to match automatically.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes