GetString with numeric values in Option List issues


#1

All,

I am having issues understanding how to present to the user numeric values when my input list for GetString.AddOptionList contains numeric values. I have checked the types of all objects in my list and they are in fact strings, however any numeric values will not show up. If I have a mixed list with (1,2.0,Three,Four) the user is only presented with Three and Four as options.

Any insight would be greatly appreciated.

Joel


(Menno Deij - van Rijswijk) #2

Any option name may not start with a numeric character, but it can contain numerical characters (“Option1”, “Option2”).

If you want to get a numeric value from a user it is best practice to use RhinoGet.GetNumber or RhinoGet.GetInteger. If part of a larger set of options, use GetOption.AddOptionDouble or GetOption.AddOptionInteger.

Examples at


SDK docs at
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Input_Custom_GetBaseClass_AddOptionDouble_2.htm
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Input_Custom_GetBaseClass_AddOptionInteger_2.htm


#3

^ Yep. It’s pretty annoying that I have to use some symbol infront of the number to have that selection option and then cut it out of the string afterwards…


#4

Hi @stevebaer, @dale

Add Command Line Options shows an example with a single OptionList.
Is it possible to use more than one OptionList (say three), and can we get an example of it?
Thank you in advance!


(Steve Baer) #5

You should be able to. Did you try and run into problems?


#6

Hi @stevebaer,

I did. I defined the second OptionList, added it to the GetPoint object, and then copied the:

if gp.OptionIndex()==opList2:
  listIndex2 = gp.Option().CurrentListOptionIndex
continue

But still I never get the chosen “listIndex2”. Only it initially defined value.

Is it possible to provide an example with at least two OptionList please?


(Steve Baer) #7

Here’s a tweaked version of the sample

import Rhino
import scriptcontext

def CommandLineOptions():
    # For this example we will use a GetPoint class, but all of the custom
    # "Get" classes support command line options.
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("GetPoint with options")

    # set up the options
    intOption = Rhino.Input.Custom.OptionInteger(1, 1, 99)
    dblOption = Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9)
    boolOption = Rhino.Input.Custom.OptionToggle(True, "Off", "On")
    listValues = "Item0", "Item1", "Item2", "Item3", "Item4"
    list2Values = "Bear", "Duck", "Zebra"

    gp.AddOptionInteger("Integer", intOption)
    gp.AddOptionDouble("Double", dblOption)
    gp.AddOptionToggle("Boolean", boolOption)
    listIndex = 3
    opList = gp.AddOptionList("List", listValues, listIndex)
    list2Index = 1
    opList2 = gp.AddOptionList("Animal", list2Values, list2Index)
    while True:
        # perform the get operation. This will prompt the user to
        # input a point, but also allow for command line options
        # defined above
        get_rc = gp.Get()
        if gp.CommandResult()!=Rhino.Commands.Result.Success:
            return gp.CommandResult()
        if get_rc==Rhino.Input.GetResult.Point:
            point = gp.Point()
            scriptcontext.doc.Objects.AddPoint(point)
            scriptcontext.doc.Views.Redraw()
            print "Command line option values are"
            print " Integer =", intOption.CurrentValue
            print " Double =", dblOption.CurrentValue
            print " Boolean =", boolOption.CurrentValue
            print " List =", listValues[listIndex]
            print " Animal =", list2Values[list2Index]
        elif get_rc==Rhino.Input.GetResult.Option:
            if gp.OptionIndex()==opList:
              listIndex = gp.Option().CurrentListOptionIndex
            if gp.OptionIndex()==opList2:
              list2Index = gp.Option().CurrentListOptionIndex
            continue
        break
    return Rhino.Commands.Result.Success


if __name__ == "__main__":
    CommandLineOptions()

(Dale Fugier) #8

Hi @djordje,

Here is another example of a Get that has multiple options lists.

https://github.com/mcneel/rhino-developer-samples/blob/6/rhinocommon/cs/SampleCsCommands/SampleCsOptionsList.cs

– Dale