C#: How to update all sliders and run the simulation once

Hi,

I try to develop a component, which is able to controll sliders, can trigger the solution process and is able to read updated number parameters after a solution run. It worked quite fine with Rhino 5 - but due to the update to version 6, I have got some trouble.

Aim:

  1. Update some slider values
  2. Perform solution once
  3. Read number values

Current behavior in v6:
After each slider change the solution is calculating

Current code example:

        // Update some slider values 
        var doc = component.OnPingDocument();
        foreach (var guid in guids)
        {
            var sliderObject = doc.FindObject(guid, true);
            if (sliderObject is Grasshopper.Kernel.Special.GH_NumberSlider)
            {
                Grasshopper.Kernel.Special.GH_NumberSlider slider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderObject;
                slider.Slider.Value = (decimal)para.Value;
                slider.ExpireSolution(false);
            }
        }

       // Perform Solution
       doc.NewSolution(false);

        // Read values
        double value = Double.NaN;
        var numberObject = doc.FindParameter(guid);
        if (numberObject is Grasshopper.Kernel.Parameters.Param_Number)
        {
            Grasshopper.Kernel.Parameters.Param_Number number = (Grasshopper.Kernel.Parameters.Param_Number)numberObject;
            if (number.VolatileData.PathCount > 0)
            {
                value = ((GH_Number)number.VolatileData.get_Branch(number.VolatileData.Paths[0])[0]).Value;
            }
        }

I thought I would get this behavior:

ExpireSolution(True): It sets the ‘expired’ flag on the component you call this method on and all objects that depend on that component. Basically everything downstream of it. When it’s done setting all these ‘expired’ flags, it will place a call to GH_Document.NewSolution(False).
ExpireSolution(False): Does the same as the previous one, except it doesn’t tell the document to re-solve itself. Use this method if you want to expire a bunch of different components before attempting a new solution.
NewSolution(True): This will set the ‘expired’ flags of all components inside the document and resolves everything. This is carpet bombing, rarely should you use this method.
NewSolution(False): This will only resolve those objects that have their ‘expired’ flags set.

Looking forward to get any help. Thanks!

Cheers,
Daniel

I think that’s the problem. When the slider control hosted inside a slider canvas object changes the UI will respond to that immediately. You’ll either have to disable the internal slider events, or use one of the top-level methods to change the value which are smart enough to only expire the object without triggering a new solution:

slider.Slider.RaiseEvents = false;
slider.Slider.Value = (decimal)para.Value;
slider.Slider.RaiseEvents = true;
slider.ExpireSolution(false);
slider.SetSliderValue((decimal)para.Value);