Python: rs.GetString will not display option strings if they contain a dot

I think this is bug.
It will properly display the default string, but not the option strings

strPrompt = "Make a choice "
strOptions = ["Option.one","Option.two","Option.three"]
PressAngle = rs.GetString(strPrompt,strOptions[1],strOptions)

Also if strOptions = [“10”,“20”,“30”]
forcing the user to choose discreet numbers non of them show up

Hi @ThomasAn_,

Command option names must only consist of letters and numbers (no characters list periods, spaces, or dashes).

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Input_Custom_GetBaseClass_AddOption_2.htm

– Dale

What is the reason for this limitation ?
I am talking about the GetString method. This is basically script specific stuff and nothing to do with Rhino commands. I think the Command(commandString, echo=True) is the one that interacts with Rhino and should to be kosher.

Hi @ThomasAn_,

I’m sure the rule is enforced by Rhino’s command line parser.

Also, rs.GetString is it self a Python function which calls into RhinoCommon and uses the AddOption method I referenced above.

– Dale

Yes, I understand, but this is the “How” it happens.
What I don’t understand is the “why”; the design decision for the limitation. Why am I not allowed to ask the user to choose discreet numbers for my own script commands ?

I should be able to ask this on my own script

strPrompt = "Choose one of the three incline level angles"
strOptions = ["15 degree","30 degree","45 degree"]
PressAngle = rs.GetString(strPrompt,strOptions[1],strOptions)

This seems like a workable solution:

import rhinoscriptsyntax as rs
strPrompt = "Choose one of the three incline level angles"
strOptions = ["Angle15","Angle30","Angle45"]
PressAngle = rs.GetString(strPrompt,strOptions[1],strOptions)

– Dale

The reason I brought it up is not my lack of imagination in workarounds, but because I have OCD on proper UI and usability. We could install doors in your house that only open 10 degrees, which should be enough for a person most of the time. if you ever need more room you could simply workaround by unscrewing the hinges for one rare occasion.

In my book it is a mini instance of poor API (an arbitrary limitation that doesn’t serve a valid purpose to the client). I brought it up, you don’t mind it. Case closed.

1 Like

Hi @ThomasAn_,

Here is another option you might consider:

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
strPrompt = "Choose one of the three incline level angles"
strOptions = ["15°","30°","45°"]
PressAngle = rs.GetString(strPrompt,strOptions[1],strOptions)

I’ve added a wish to the pile (I’m pretty sure this has already been logged):

https://mcneel.myjetbrains.com/youtrack/issue/RH-50714

If the command line UI is insufficient, then you might consider display a dialog box.

– Dale

Being able to use more types of characters as command options in Rhino.GetString would be - well… revolutionary. It would allow much more elegant command line UI for small and bigger scripts. It’s been one of the biggest limitations in my 10+ years of RhinoScripting, and I never understood why this limitation is there, while regular Rhino commands handle more characters. Please consider allowing this also for Rhino.GetString method :slight_smile:

thanks,

–jarek

1 Like

Keeping mind that Rhino.GetString just add strings options using the equivalent of RhinoCommon’s GetBaseClass.AddOption method, can you provide an example of what you’ve stated?

– Dale


So here regular Rhino command (Offset) allows for “=”, and “.” characters.
This is already great, if could be replicated via Rhino.GetString method.

Currently apart from numbers and characters, only “_” (underscore) is allowed. One of many limitations of this, apart from lack of elegance, is inability to display decimal values this way.

Sampe RS code:

    Dim arrOptions,strResult
    arrOptions = array("Option1", "Option2", "Option_3")
    strResult = Rhino.GetString("Select Option", "", arrOptions)

–jarek

@Jarek,

What you’ve highlighted is provide GetBaseClass.AddOptionNumber, not the GetBaseClass.AddOption method I referenced prior.

If you want this kind of fanciness in RhinoScript, then you should be using GetOption, not GetString.

– Dale

3 Likes

That would solve everything ! Where is it ?
It is not in Python via rhinoscriptsyntax ?

Thanks Dale, it was a nice addition to RS, a bit more complicated to use than GetString, especially for nested mixed options, but yes, it does allow for all that is needed.
Allowing special characters in GetString would allow to make things simpler to code sometimes, but if not achievable we can switch to GetOption for fancier command-line menus.

@ThomasAn_ - this was a recent addition to V6 RhinoScript; many of these did not make it to RhinoScriptSyntax so this one also may be not implemented, unfortunately. It would be great if the two tracks were more in-synch. While Python allows to do much more sophisticated stuff if you dive into RhinoCommon, on a pure simple scripting level RhinoScript has more methods implemented (thanks @Dale)