Grasshopper

algorithmic modeling for Rhino

Hi guys, 

Is there an Event to detect if the value of an input parameter has changed? 
I tried Component.Params.ParameterChanged which is working if another component is connected, but not if the value is changed. 

This is what I am trying to achieve: If the dropdown component is changed, the c#-component should update the slider...
It is also working with GH_Document.SolutionEnd Event but as far as I understand, this will recompute the whole solution. So if there is a huge script following downstream, this will be called always twice (correct?). 
I would like the script to:

1. detected the change of an input parameter value
2. stop the script and 
set a few sliders
3. continue computing downstream stuff.

Thanks in advance!

private void RunScript(System.Object mySliders, bool startme, ref object A)
{
    if (!startme)
    return;

    if (_running)
        return;

    _run = true;

    Component.Params.ParameterChanged += new                   GH_ComponentParamServer.ParameterChangedEventHandler(OnSolutionEnd);

}

// <Custom additional code>
private bool _run = false;
private bool _running = false;

private void OnSolutionEnd(object sender, GH_ParamServerEventArgs e)
{
    // Unregister the event, we don't want to get called again.
    Component.Params.ParameterChanged -= OnSolutionEnd;

    // If we're not supposed to run, abort now.
    if (!_run)
        return;

    // If we're already running, abort now.
        if (_running)
        return;

    // Reset run and running states.
    _run = false;
    _running = true;

    foreach (IGH_DocumentObject obj in GrasshopperDocument.Objects)
    {
        if(obj is Grasshopper.Kernel.Special.GH_NumberSlider)
        {
            var slider = obj as Grasshopper.Kernel.Special.GH_NumberSlider;
            slider.TickValue = 9;
            _running = false;
         }
    }
}

Views: 1778

Replies to This Discussion

No, data is never 'changed' in that way. What happens is the parameter expires (there's an event for that), at which point it erases all current data. Then, later when the solution runs, the parameter collects all the data again, be it from sources or from persistent data. This new data may be the same as the old data, or it may be entirely different, the parameter does not try to determine this.

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