Rhino.Input.Custom.GetNumber() with Optionlist

image

I need a list of predefined numbers to choose from or to input a custom number.

I assume I have to use Rhino.Input.Custom.GetNumber()
But numbers won’t work with AddOption

So I don’t know how to do this.
Thanks for helping.

Hi @Bogdan_Chipara,

that has never been possible since you’ll need to be able to enter numbers to the prompts. You may add a letter prefix eg “X_100” to circumvent it, though. To test if an option name qualifies for beeing valid or not you can use:

import Rhino
text = "100"
print Rhino.Input.Custom.CommandLineOption.IsValidOptionName(text)

_
c.

Hi @Bogdan_Chipara,

This is the same question, correct?

– Dale

Hi @dale

Is not the same.
I need a list and the option to input a custom number.
GetOption works with AddOptionList
GetNumber doesn’t work with AddOptionList

@clement adding a prefix will not solve the issue, i still need to have the possibility to input a custom number instead of the ones available in the list.

Hi @Bogdan_Chipara,

AddOptionList works with the same with “Get” class that inherits from GetBaseClass. So I don’t understand your comment.

If you have code that doesn’t work for you, then please provide.

Thanks,

– Dale

Hi @Bogdan_Chipara, you might do this using GetOption and AcceptNumber:

https://developer.rhino3d.com/api/rhinocommon/rhino.input.custom.getbaseclass/acceptnumber

_
c.

@clement I also tried AcceptNumber . I couldn’t make it work with it either.

I guess i hacked the System using a hairspace:

import Rhino

def DoSomething():
    
    go = Rhino.Input.Custom.GetOption()
    go.SetCommandPrompt("Choose or enter a number")
    go.AcceptNumber(True, False)
    for n in range(10, 310, 10): go.AddOption("{}{}".format(u"\u200A", n))
    
    while True:
        get_rc = go.Get()
        if go.CommandResult() != Rhino.Commands.Result.Success: return
        if get_rc == Rhino.Input.GetResult.Number:
            return go.Number()
        break

print DoSomething()

better to use “mm” or whatever prefix or suffix to be on the safe side :wink:

_
c.

3 Likes

thanks @clement This is exactly what I need.

If I need custom values I can just add them one by one as below.

import Rhino

def NumberWList():
    
    go = Rhino.Input.Custom.GetOption()
    go.SetCommandPrompt("Choose or enter a number")
    go.AcceptNumber(True, False)

    go.AddOption("100mm")
    go.AddOption("150mm")
    go.AddOption("200mm")
    
    go.Get()
    return go.Number()
       
print (NumberWList())

Rhino Common is just too complicated for me. I much prefer to play with rhinoscriptsyntax. But with examples like this I can learn a bit more.

Hi @dale ,
My code was not working because I am a bad computer programmer and I don’t understand RhinoCommon.
It is a very large library which also works in a different way than rhinoscriptsyntax does.
Thanks to @clement I revised the code to work.

What I really miss with RhinoCommon is simple examples on how to use the classes and methods on https://developer.rhino3d.com/api/rhinocommon/?version=8.x

Examples made out of 2 - 3 lines of code resumed to the essential. Without while loops and if statements required for a proper code. Stripped to the bone indications of working code might help people like me to learn RhinoCommon.

Kind regards

@clement , @dale I need your help again.

On my above script, for NumberWList() how do I add one more variable with go.AddOption(“Session_variable”) that remembers the value for an entire Rhino session.

I should still have the option list 100mm, 150mm, 200mm followed by Session_variable.
When I click on it, I should have the possibility to input a Number.
This Number will be the same for the whole session, unless, changed again.

Thank you again for detailing this topic of Rhino.Input.

Hi @Bogdan_Chipara, try if below helps:

import Rhino
import scriptcontext as sc

def DoSomething():
    go = Rhino.Input.Custom.GetOption()
    go.SetCommandPrompt("Choose or enter a number")
    go.AcceptNumber(True, False)
    for n in range(10, 110, 10): go.AddOption("{}{}".format(n, "mm"))
    
    key = "MyCustomNumber"
    number = sc.sticky[key] if sc.sticky.has_key(key) else 42
    optCustomNumber = Rhino.Input.Custom.OptionInteger(number, True, 1)
    go.AddOptionInteger("CustomNumber", optCustomNumber)
    
    while True:
        get_rc = go.Get()
        if go.CommandResult() != Rhino.Commands.Result.Success: return
        if get_rc == Rhino.Input.GetResult.Number:
            return go.Number()
        if get_rc == Rhino.Input.GetResult.Option:
            if go.Option().EnglishName == "CustomNumber":
                number = optCustomNumber.CurrentValue
                sc.sticky[key] = number
                return number
        break

print DoSomething()

When you click on the CustomNumber option, you can enter a new number which will be remembered for next run. If you click on it and press Enter, it should return the last used number…
_
c.

1 Like

I give up,

There are more lines of code to setup the prompt than the atual code that I want to run…

for this, nice would be, a visual interface to drag-and-drop options and such…