It’s logical to consider that the order of the code in your rule can determine whether it needs to be run twice to complete or not, however there is another cause for this that many people are unaware of and that’s what I will cover today.
The
different types of Parameters.
There
are two different types of Parameters and they both behave differently which
can affect the outcome once a rule has run. This first type is the most common
parameter- the “double click the name in the rule editor” blue parameter.
This
parameter does what it needs to, including updating in the rule if you rename
the parameter in your model. This Parameter will hold onto a value, and only change
to that value when the rule finishes executing.
This
characteristic of the blue parameter can cause problems.
Let’s
examine the example below.
If
I know Frame_Width is 100 when my rule starts, I expect the code to make the
Length of the Horizontal_SHS component 200. But that’s not the case. The reason
for that is after changing the Frame_Width to 200, we now know it will hold
that value until the rule finishes, then update to 200. As a result, the
Frame_width that is used to drive the length of the SHS part is still 100.
Running the rule a second time will cause Frame_Width to be the expected 200
and the component will update correctly.
There
is a way around this characteristic, and here Parameter type becomes useful.
Enter
the Purple and green parameter, technically referred to as a “Dynamic
Parameter”. This parameter uses a String indicated by the “Quotation marks” and
won’t update on its own if you change the name of the parameter. On the surface
they play the same role, however the dynamic Parameter alters the outcome.
If
I was to run the same code but using a dynamic parameter instead of the normal
blue parameter, we would get the desired result the first time.
The
reason for that is a dynamic Parameter forces the parameter to take the new
value as soon as its set instead of waiting for the end of the rule. After the
first line, Frame_Width will be 200, and as a result the Length of the SHS part
will be 200.
If
you find your rules need to run twice, check the order of the code in the rule
remembering it runs top to bottom followed by what type of parameters are
getting the values needed to execute correctly. For tricky cases, combine your
checks with the iLogic Logger in my previous Episode.
With each Inventor release, Autodesk adds new features and abilities in iLogic, so if you’ve used it before or considering using it, contact us. We provide various iLogic training from the very basics to more tailored courses to help you get up to speed with iLogic.
No comments:
Post a Comment