Command line options to update Option values

I am struggling to create a simple command line option. My new command allow the user to select object and has option to enter a double.

Because my command has only 1 option, I thought what I want to do is when the user enter a number, it will update the option.

My questions are:

  1. How do I update the current double options? I have added the line

         else if (result == GetResult.Number)
         {
            doubleOption.CurrentValue = go.Number();
            continue;
         }
    

It does update the doubleOption, but the prompt that comes up next again still got the old number.

  1. When I run the same command 2nd time, is there a way to restore the last used Double Option?

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
    // For this example we will use a GetPoint class, but all of the custom
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt(“Select closed curve”);

      // set up the options
      Rhino.Input.Custom.OptionDouble doubleOption = new Rhino.Input.Custom.OptionDouble(50);
    
      go.AddOptionDouble("Double", ref doubleOption);
      go.AcceptNumber(true, true);
      go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
      go.GroupSelect = true;
      go.SubObjectSelect = false;
      go.EnableClearObjectsOnEntry(false);
      go.EnableUnselectObjectsOnExit(false);
      go.DeselectAllBeforePostSelect = false;
      go.EnableSelPrevious(true);
      go.EnablePreSelect(true, false);
      go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    
      bool bHavePreselectedObjects;
    
      while (true)
      {
         // perform the get operation. This will prompt the user to select the list of curves, but also
         // allow for command line options defined above
         GetResult result = go.GetMultiple(1, 0);
    
         if (result == GetResult.Option)
         {
            go.EnablePreSelect(false, true);
            continue;
         }
         else if (result == GetResult.Number)
         {
            doubleOption.CurrentValue = go.Number();
            continue;
         }
         else if (result != GetResult.Object)
         {
            return Result.Cancel;
         }
    
         if(go.ObjectsWerePreselected)
         {
            bHavePreselectedObjects = true;
            go.EnablePreSelect(false, true);
            continue;
         }
    
         break;
      }
    
      int objecTCount = go.ObjectCount;
    
    
      return Result.Success;
    

    }

I’m not exactly sure what you’re trying to do with all the selection options, but that should not matter. The bare-bones functionality for getting an object with a double option on the commandline is this

protected void RunCommand(RhinoDoc doc, RunMode mode)
{
    double value = Settings.GetDouble("KEY_TO_VALUE", 50.0);

    ObjRef oRef;
    GetObject go = new GetObject();
    OptionDouble opt;
    while (true)
    {
        go.ClearCommandOptions();

        opt = new OptionDouble(value);
        go.AddOptionDouble("Double", ref opt);

        GetResult gr = go.Get();
        if (gr == GetResult.Cancel)
            return Result.Cancel;

        if (gr == GetResult.Object)
        {
            oRef = go.Object(0);
            break;
        }

        if (gr == GetResult.Option)
        {
            value = opt.CurrentValue;
        }
    }

    value = opt.CurrentValue;
    // do something with oRef

    //store newly selected value for next use
    Settings.SetDouble("KEY_TO_VALUE", value);

    return Result.Success;

}

Thanks Menno, you have answered my 2nd question.

However, for my first question, I do not have a solution.

What I wanted to do is to update the value of the double option to the value I typed in.

e.g. When the prompt says

Select closed curve (Double=50):

If I type in 5 and then Enter, I want the console to prompt

Select closed curve (Double=5):

At the moment, it does prompt again, but it reads

Select closed curve (Double=50):

But when I type in “D” to review the Double option
the value has been updated to 5.

Any ideas?

@TobyLai,

have you tried to put this above the loop and not inside:

opt = new OptionDouble(value);
go.AddOptionDouble("Double", ref opt);

@menno i have not understood yet why you used:

go.ClearCommandOptions();

???
_
c.

@menno
Sorry menno, your solution actually works, I re-created the commandOptions in the loop, so it becomes a new value.

Thanks Clement for pointing that out.