gh_py_slider_Value, No change output to "gh"

I write in the “gh” eto, I want to make the slider value changes appeared in the “gh”, “ghenv.Com ponent. ExpireSolution (True)” this can’t seem to refresh the value of the slider

"""Grasshopper Script"""
import Eto.Forms as ef
import Eto.Drawing as ed

slider_Value = 3

form = ef.Form()
form.Width = 100
form.Height = 100

m_slider = ef.Slider()
m_slider.MaxValue = 10
m_slider.MinValue = 0
m_slider.Value = 3

m_label = ef.Label()
m_label.Text = str(3)

def slider_Changed(s,e):
    m_label.Text = str(m_slider.Value)
    ghenv.Component.ExpireSolution(True)

m_slider.ValueChanged += slider_Changed

layout = ef.DynamicLayout()
layout.AddRow(m_slider,None,m_label)

form.Content = layout
form.Show()

slider_Value = m_slider.Value


unnamed.gh (4.6 KB)

I tried asking for help @dale @DavidRutten

@tom33

You’d need to manually assign the data on the output parameter of script component since you don’t want the component to ‘run’ many times as you are changing the slider value. Then you need to expire all downstream components that are connected to your output value:

import Eto.Forms as ef
import Eto.Drawing as ed
from Grasshopper.Kernel import IGH_Param
from Grasshopper.Kernel import GH_ActiveObject
from Grasshopper.Kernel.Types import GH_Number


# function to set a single value on an output parameter
def set_output(name, value):
    for output in ghenv.Component.Params.Output:
        if output.NickName == name:
            path = output.VolatileData.Paths[0]
            branch = output.VolatileData.get_Branch(path)
            if branch:
                branch[0] = GH_Number(value)


# function to expire all downstream connected components
def expire_downstream():
    for out in ghenv.Component.Params.Output: # type: IGH_Param
        for r in out.Recipients: # type: GH_ActiveObject
            r.ExpireSolution(True)


form = ef.Form()
form.Width = 100
form.Height = 100

m_slider = ef.Slider()
m_slider.MaxValue = 10
m_slider.MinValue = 0
m_slider.Value = 3

m_label = ef.Label()
m_label.Text = str(3)

def slider_Changed(s,e):
    m_label.Text = str(m_slider.Value)

    # set value and expire
    set_output('slider_Value', m_slider.Value)
    expire_downstream()

m_slider.ValueChanged += slider_Changed

layout = ef.DynamicLayout()
layout.AddRow(m_slider,None,m_label)

form.Content = layout
form.Show()

unnamed.gh (5.2 KB)

2 Likes

This is useful for me. I need to look into it

1 Like