While/Do Until/Do While Loop condition not updating

While/Do Until/Do While Loop condition not updating

nico.villarica2U5YQ
Participant Participant
824 Views
5 Replies
Message 1 of 6

While/Do Until/Do While Loop condition not updating

nico.villarica2U5YQ
Participant
Participant
Parameter.UpdateAfterChange = True

If WithMeter = True Then
    i = 0
    Do Until (Parameter("BoxWidthFinal") > 550)
            Parameter("Offset_BoxWidth") = Parameter("Offset_BoxWidth") + 5
            i = i + 1
            If i = 50 Then
            MessageBox.Show("Iterations exceeded expected value. Exiting loop.", "Warning")
                Exit Do
            End If
    Loop
    'iLogicVb.UpdateWhenDone = True
Else
    Parameter("Offset_BoxWidth") = 0.001
End If

iLogicVb.UpdateWhenDone = True

Please help I'm having difficulty making this loop work. No matter what I do the loop always ends at i = 50 even when the parameter "BoxWidthFinal" should have already gone past 550.
Btw, parameter BoxWidthFinal is defined as (BoxWidthfinal = BoxWidth + Offset_BoxWidth) in a separate rule.
My guess is that the loop condition isn't updating after each iteration of the loop.

Also I have a similarly constructed loop within the same .ipt file in another rule, which adjusts another parameter (BoxDepth). That seems to work but this one does not.

 

0 Likes
Accepted solutions (1)
825 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

According to the help document here you may need to remove the update when done and add the below combinations to have it update loop by loop. 

 

  • Parameter.UpdateAfterChange = True

    True will cause the model (document) to Update after a parameter value is changed by the Parameter function. This only takes effect when you change parameters using the Parameter function. For example:

  • Parameter.UpdateAfterChange = True
  • Parameter("d0") = 2.5

    This will update the model.

    Note: ("d0") = 2.5 will NOT update the model.
To update the model in the middle of the rule (after changing some parameters) use these two statements together:
    • RuleParametersOutput()
      Note: - This will assign the current values of the parameter local variables to the model.
    • InventorVb.DocumentUpdate()

If you do not need to update the model in the middle of the rule, you can tell the system to update when it has finished running the rule. Use this statement: iLogicVb.UpdateWhenDone = True.

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

WCrihfield
Mentor
Mentor

Hi @nico.villarica2U5YQ.

Maybe this is too simplistic, but what is the initial numerical value of 'BoxWidthFinal'?  If it is less than 300, then it will take more than 50 times of adding the value of 5 to it to get to 550, so it will always hit the limit of 50 iterations before reaching that value limit.  (5 x 50 = 250, so you will only have added a value of 250 to the 'BoxWidthFinal' value after 50 iterations of adding 5 to it.)

 

Also, keep in mind that raw numbers in an iLogic rule will be understood as being in 'database units', which for distance is centimeters.  So if your parameter is not in centimeters units, you may have to do some extra math to convert 5 centimeters to 5 of the units that you are using in your parameter.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

nico.villarica2U5YQ
Participant
Participant
Hi @WCrihfield,
The initial value of BoxWidthFinal is 420. I then always end up with a final value of 670, which means it has already cycled through all 50 counts of the loop, which should have stopped at i = 27 (which yields BoxWidthFinal = 555).
0 Likes
Message 5 of 6

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

You wrote your Parameter BoxWidthFinal is calculated in another rule as sum of BoxWidth and Offset_BoxWidth. To update the value of BoxWidthFinal this other rule calculates, you have to run it in your loop every time your Offset_BoxWidth is raised. Otherwise BoxWidthFinal will be constant.

Alternative, add "BoxWidth + Offset_BoxWidth" to the expression of BoxWidthFinal in the fx-parameter dialog.


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

nico.villarica2U5YQ
Participant
Participant
Hi @Anonymous,

You're absolutely right the rule that contains the expression for BoxWidthFinal has to be run every time Offset_BoxWidth is raised. I figured the issue was something like that.
I couldn't do what you suggested about defining the parameter in the fx parameter dialog since the definition for BoxWidthFinal changes depending on other conditions, so I just added the command iLogicVb.RunRule("BoxWidthRule") to the aforementioned loop.

It works now, thanks a lot!
0 Likes