How to get max value from number slider?

I have a number slider with integer values. Now, I want to use the max value from that slider as 100% in a different operation. How do I output the max value from the number slider?

You could try popping this into a GHPython component. Where Input[0] represents the top/first input in the ghpython component (x in the screenshot), and there is only 1 source plugged in, (your number slider with integer values).

import Rhino

print ghenv.Component.Params.Input[0].Sources[0].TickCount

1 Like

Thank you! (Found it.)

Also, wow, I thought this was a super basic question, but already it seems I’ve stumbled on something that requires a super advanced solution.

Is there any other way one normally inputs min/max/interval numbers into Grasshopper?

Strictly from a technical standpoint, (as far as I know…), there is no other way to capture the maximum value setting of a slider. (outside of a scripting component, C#, VB, ghpython, or other specialized plugin).
With that said…would the maximum value of a slider ever change for some reason?

The most basic way to input min/max interval numbers would probably be to just use the construct domain component? You input min, max, and it outputs an interval…

No, it probably wouldn’t change since I can just set it crazy high, but I also can’t ever see it unless I open the slider editor, which is bad.

Can I ask what node you used to output the value with, because I used the param viewer node and that didn’t display correctly.

Plus, one final detail, your script actually seems to output the range, not the max, but adding +1 to it fixed that.

Oh, and can I also ask how to get the nice colored icon in the node like in your screenshot? Mine only has text.

ah, that’s fair, I just looked quickly. My slider was set from 0 to 50. Let me see if there is another property that might specifically have the max value.
Also, the node connected to the output value is a panel.

In GH, go to Display->Draw Icons to draw the icons. This will change the display for all components. You can also do it on a per component basis by right clicking the component, and click the little paint bucket next to the component name to toggle through some options.

1 Like

Try this one. I didn’t dig down enough to get to the proper object.

sourceSlider = ghenv.Component.Params.Input[0].Sources[0].Slider
print sourceSlider.Maximum

also, I would guess that something like Human or Metahopper (pre built plugins) , might already have some of this type of stuff built in.

4 Likes

Wonderful, thanks again!

@chanley
Hi Chris, sorry for reactivating this so late but… I have been digging around the docs for an hour to figure this out and was this far:

sO = pS.Input[0].Sources[0]
print(type(sO)) #returns GH_NumberSlider
print(sO.Maximum) #fails with error "no attribute Maximum"

#create a new slider and see if it has maximums
sl = Grasshopper.GUI.GH_Slider() 
print(sl.Maximum) #works fine...

Apart from me being confused by not finding any information regarding GH_NumberSlider in the docs (GH_Slider yes) my question to you is:

how did you come up with this :

sourceSlider = ghenv.Component.Params.Input[0].Sources[0].Slider

what does the “.Slider” in the end do ? What is this called? Is it a form of type casting? What keyword can give me more information on this topic and which part of the docs tells me to use this :smiley: ?

Anyhow, thanks a bunch!
Best regards
Malte