# Is something like "AddOptionString" possible?

**URL:** <https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327>\
**Category:** Rhino Developer\
**Tags:** rhinocommon, getpoint\
**Created:** [June 2, 2020, 5:31pm UTC](https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327 "2020-06-02T17:31:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![josien](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/josien/32/183673_2.png) [@josien](https://discourse.mcneel.com/u/josien)\
**Post date:** [June 2, 2020, 5:31pm UTC](https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327/1 "2020-06-02T17:31:26Z")

</div>

Hi.

Is it possible to add a user input string to the options as in the image?  
The user would take the following steps:

1. Press “String=default value”
2. Type a custom string as input
3. Press enter
4. Automatically go back to the same menu as in the image
5. Press enter and continue the command

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/6/4/641f4d533c37cf727a3e5af3535568cd1b9a6655.png)

The situation in the image comes from this code example: [https://developer.rhino3d.com/samples/rhinocommon/add-command-line-options/](https://developer.rhino3d.com/samples/rhinocommon/add-command-line-options/)

Your answers would be greatly appreciated.

Josien

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [June 2, 2020, 5:38pm UTC](https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327/2 "2020-06-02T17:38:26Z")

</div>

I think what you want is found in `AddOption` see  
[https://developer.rhino3d.com/api/RhinoCommon/html/M\_Rhino\_Input\_Custom\_GetBaseClass\_AddOption\_3.htm](https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Input_Custom_GetBaseClass_AddOption_3.htm)

You can add a `OptionName=String Value` on the command line.

---

<div class="post-metadata">

**Author:** ![josien](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/josien/32/183673_2.png) [@josien](https://discourse.mcneel.com/u/josien)\
**Post date:** [June 3, 2020, 9:13am UTC](https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327/3 "2020-06-03T09:13:01Z")

</div>

Actually, I don’t think this solves my problem. What I want, is that the user can then _type_ his/her own string.

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [June 3, 2020, 10:00am UTC](https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327/4 "2020-06-03T10:00:14Z")

</div>

Hold my beer… I know this can be done.

```auto
public Result RunCommand(RhinoDoc doc, RunMode mode)
{
  GetPoint gp = new GetPoint();
  string chosenString = "default value";
  Point3d chosen;
  while (true)
  {
    gp.ClearCommandOptions();
    int stringOption = gp.AddOption("String", chosenString);
    GetResult gr = gp.Get();
    if (gr == GetResult.Point)
    {
      chosen = gp.Point();
      break;
    }

    if (gr == GetResult.Option)
    {
      if (gp.OptionIndex() == stringOption)
      {
        GetString gs = new GetString();
        gs.SetCommandPrompt("Type your string");
        GetResult stringGetResult = gs.GetLiteralString();
        if (stringGetResult == GetResult.String)
        {
          chosenString = gs.StringResult();
        }
      }
    }
  }

  RhinoApp.WriteLine("Chosen string: " + chosenString);

  return Result.Success;
}

```

---

<div class="post-metadata">

**Author:** ![josien](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/josien/32/183673_2.png) [@josien](https://discourse.mcneel.com/u/josien)\
**Post date:** [June 3, 2020, 2:24pm UTC](https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327/5 "2020-06-03T14:24:42Z")

</div>

Wow, that works! Thanks a lot. I will be working a bit more on what I want to achieve and then post the end result here.

I also have a follow up question: what if you actually don’t want a GetPoint?  
What I want to achieve is that the user can choose some options from the same menu, then press enter and continue (without getting a point).

To clear up, the user would type the command, then enter a menu like this:  
nlsfb\_code = 22.23 building\_part\_id = FA simple\_element\_name = Roof Beam  
(In this menu the user can click an option, then type his/her alternative string, press enter and go back to the menu)  
Then, the user presses enter, the command continues and the values are used later in the code.

Long story short, is something like a GetNothing 🙂 possible ?

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [June 3, 2020, 2:40pm UTC](https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327/6 "2020-06-03T14:40:09Z")

</div>

Yes, instead of `GetPoint` use `GetOption`. Of course, it will never return `GetResult.Point`, so you should do the following with `AcceptNothing(true)`:

```auto
GetOption go = new GetOption();

// this will return GetResult.Nothing if the user presses Enter:
go.AcceptNothing(true); 
while(true)
{
  go.ClearCommandOptions();
  // build your options with currently defined values
  // ...
  // ...

  // get the current state from the user
  GetResult gr = go.Get();
  if (gr == GetResult.Nothing) break;
  if (gr == GetResult.Option) 
  {
    // process option that was changed
  }
}
```

---

<div class="post-metadata">

**Author:** ![josien](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/josien/32/183673_2.png) [@josien](https://discourse.mcneel.com/u/josien)\
**Post date:** [July 9, 2020, 8:25am UTC](https://discourse.mcneel.com/t/is-something-like-addoptionstring-possible/103327/7 "2020-07-09T08:25:28Z")

</div>

@menno Firstly, I found a small mistake in your code. I couldn’t cancel the command, it would just stay in the loop forever unless you actually drew a point / chose an option.

As promised, here is my finished code 🙂 :

```
OptionToggle newOverwriteToggle = new OptionToggle(true, "Overwrite", "New");
            OptionDouble manuAreaOption = new OptionDouble(manuArea);
            OptionDouble manuMaterialPriceOption = new OptionDouble(manuMaterialPrice);
            OptionDouble labourHoursOption = new OptionDouble(labourHours);
            OptionDouble toolsPriceOption = new OptionDouble(toolsPrice);

            GetOption go = new GetOption();
            go.SetCommandPrompt("Settings");
            go.AcceptNothing(true);
            while (true)
            {
                go.ClearCommandOptions();
                if (!newElement) go.AddOptionToggle("Mode", ref newOverwriteToggle);
                int plateOptIndex = go.AddOptionList("Plate", plateNames, plateIndex);
                int buildingPartOptIndex = go.AddOptionList("BuildingPart", buildingPartNames, buildingPartIndex);
                int nlsfbOptIndex = go.AddOptionList("NLSFB", nlsfbRegCodes, nlsfbIndex);
                int ifcEntityOptIndex = go.AddOptionList("IfcEntity", ifcEntities, ifcEntityIndex);
                int elementSimpleOptIndex = go.AddOption("SimpleElementName", elementNameSimple);
                go.AddOptionDouble("ManualAreaM2", ref manuAreaOption);
                go.AddOptionDouble("ManualMaterialPrice", ref manuMaterialPriceOption);
                go.AddOptionDouble("LabourHours", ref labourHoursOption);
                go.AddOptionDouble("ToolsCost", ref toolsPriceOption);
                
                RhinoApp.WriteLine("Element size is {0} mm x {1} mm.", width, length);

                GetResult gr = go.Get();
                if (go.CommandResult() != Rhino.Commands.Result.Success)
                    return go.CommandResult();

                if (gr == GetResult.Nothing)
                {
                    if(!newElement) newVersion = newOverwriteToggle.CurrentValue;
                    manuArea = manuAreaOption.CurrentValue;
                    manuMaterialPrice = manuMaterialPriceOption.CurrentValue;
                    labourHours = labourHoursOption.CurrentValue;
                    toolsPrice = toolsPriceOption.CurrentValue;
                    buildingPartID = buildingPartIDs[buildingPartIndex];
                    plateID = plateIDs[plateIndex];
                    nlsfb = nlsfbCodes[nlsfbIndex];
                    ifcEntity = ifcEntities[ifcEntityIndex];
                    if(plateID == 0 || buildingPartIndex == 0 || nlsfbIndex == 0 || ifcEntityIndex == 0)
                    {
                        RhinoApp.WriteLine("Plate, Building part, NLSFB and IFCentity cannot be NULL.");
                        continue;
                    }
                    break;
                }
                if (gr == GetResult.Option)
                {
                    if (go.OptionIndex() == buildingPartOptIndex)
                    {
                        buildingPartIndex = go.Option().CurrentListOptionIndex;
                    }
                    else if (go.OptionIndex() == plateOptIndex)
                    {
                        plateIndex = go.Option().CurrentListOptionIndex;
                    }
                    else if (go.OptionIndex() == ifcEntityOptIndex)
                    {
                        ifcEntityIndex = go.Option().CurrentListOptionIndex;
                    }
                    else if (go.OptionIndex() == nlsfbOptIndex)
                    {
                        nlsfbIndex = go.Option().CurrentListOptionIndex;
                    }
                    else if (go.OptionIndex() == elementSimpleOptIndex)
                    {
                        GetString gst = new GetString();
                        gst.SetCommandPrompt("Simple Element Name");
                        if (gst.GetLiteralString() == GetResult.String)
                        {
                            elementNameSimple = gst.StringResult();
                        }
                    }
                }
            }

```

The code will not work directly if you copy paste it into your own visual studio, because there is some lists (like `plateNames`) and indexes (like `plateIndex`) that I initialized and assigned earlier in the code and it is too complex to put it here. But you can adapt the code to make it work!
