Grasshopper

algorithmic modeling for Rhino

Change NumberSlider values in a for loop, solve downstream of slider each time

I have a list of values and I would like to iterate through this list of values and set the slider value to each value as I go through the for loop.

My code is as follows:

foreach (string value in valuesToIterate)
{

this.SetSliderValue(System.Convert.ToDecimal(value));

this.Slider.OnValueChanged(false);

}

Of course, each time the slider value is changed I also want Grasshopper to solve everything downstream of that slider value.

Unfortunately the slider is only changing to a few of these values and each time it changes, I get the error pop up - Grasshopper breakpoint: An object expired during a solution.

I am guessing that I have to let Grasshopper solve before I change the slider value again, but how do I do that?

What exactly am I doing wrong here?

Many thanks!

Views: 1053

Attachments:

Replies to This Discussion

Hi,

if you use Slider.Slider.Value = val instead of using Slider.SetSliderValue(val), no error appears.

File.

Attachments:


Thanks Daniel what is the significance of 

Me.Component.ExpireSolution(True), are you expiring the solution of the component itself or the slider? I'm quite confused here because I do python and C# not vb. 

I am trying to expire the slider itself, but what I am doing doesn't work in the same way as your code. Mine just simply goes to the last value and skips everything in between.

My code is attached.

Attachments:

Me.Component.ExpireSolution(True) makes the component have to re-run.

You are changing the value of the slider N times (in a loop) and running the component once. My approach (and I think it is the usual for these cases) changes the slider once and re-runs the component N times.

To change a component remotely you have to attend to the flow of data in the definition. While a component is running, the rest of the definition does not change. When a component finishes, the other components that are missing to update in the definition are updated. Therefore, if you want another component (the slider) to be updated in each value, you must allow the definition to be executed before changing the value of the slider again.


SetSliderValue specifically prevents a new solution from being triggered. It only expires the slider and the objects that depend on it. You must trigger a new solution yourself once you are done setting new slider values.

Daniel's suggestion will cause a new solution right away, which is something you don't want if you're setting more than one slider at a time.

However I'm more worried about the specific error you're getting. The code which sets these new slider values, where does it run from? 

Hi David,

I see your point, Daniels solution will only work for one slider this means that I must use the approach that Mostapha has taken here: 

https://github.com/mostaphaRoudsari/ladybug/blob/master/src/Ladybug...

To answer your question the slider values are coming from a checklist downstream, now one of those values is actually the current value of the slider which is linked the checklist so I can see why there is a solution expired problem.

This means that when I am running this code I will have to unlink the current slider value from the checklist otherwise its a circular reference.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service