GetMultiple with Option doesn't show preselected object

I’m trying to create a command where you can select multiple objects and be able to have an option that can be changed in the commandline. But when I first select an object and then decide to enter the value in the commandline, it doesn’t show which objects were preselected in yellow. However it does remember which objects I had preselected. What am I doing wrong?

var go = new GetObject();
go.SetCommandPrompt("Select objects to be moved");
var plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
var number = 22;
OptionInteger nr = new OptionInteger(number);
go.AddOptionInteger("OffsetDistance",ref nr);
go.EnablePreSelect(true, true);
while (true)
            {
                var go_get = go.GetMultiple(1, 0);
                if (go.CommandResult() != Result.Success)
                    return go.CommandResult();
                if (go_get == Rhino.Input.GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    go.AlreadySelectedObjectSelect = true;
                    go.EnableClearObjectsOnEntry(false);
                    go.DeselectAllBeforePostSelect = false;
                    go.EnableUnselectObjectsOnExit(false);
                    number = nr.CurrentValue;
                    continue;
                }   
                break;
            }

Hi @siemen,

If you allow for pre-selection and the user pre-selects, then your options will never be displayed. In this case, check the GetObject.ObjectsWerePreselected property to see if this was the case and, if so, display your options using a GetOption object after the fact.

Make sense?

– Dale

Hi @dale ,
I don’t mean preselecting before the command starts. I mean: I start the command, I select a few objects and then I realize I need to adjust an option in the commandline. So I click on that option and change the value and then I can continue selecting objects. But after changing the option, the objects I preselected are not selected anymore (at least they’re not yellow). I would like to have them selected so I avoid selecting objects that were already part of my first selection.

Hi @siemen,

This behavior is not part of Rhino’s object picker. However, by picking a single object in a loop, you can provide this behavior. I’ve attached some code as an example.

TestSiemen.cs (1.9 KB)

– Dale

Hi @dale,
This looks like it works but this only allows me to select objects 1 by 1, which is too tedious in certain situations. How would I implement the possibility to use window selection in your example?

Hi @siemen,

Sorry no. You can always prompt for the selection of object and then prompt for the command options.

– Dale

Ah, that’s a shame. I’m kind of looking to recreate the same selection behavior like in OffsetMultiple (for example, I’m sure there are a lot of other commands with the same behavor).
Just out of curiosity: Is the reason I cannot implement the same selection behavior because it is written in C/C++?

@dale Would it be possible to enter a loop and allow for multiple objects and keeping doing that when I change a command line option, (and then also reselecting the objects after I’m done changing the command line option) until I press enter when it goes out of the loop and continues the rest of the command. Or until I press esc and then it returns failure without doing anything else?

@siemen - try this and see if it works any better.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var integer1 = 2;
  var integer2 = 4;

  var go = new GetObject();
  go.SetCommandPrompt("Select curves");
  go.GeometryFilter = ObjectType.Curve;
  go.EnableUnselectObjectsOnExit(false);
  go.EnablePreSelect(true, true);

  for (;;)
  {
    go.ClearCommandOptions();

    var option1 = new OptionInteger(integer1, 1, 100);
    var option2 = new OptionInteger(integer2, 1, 100);

    go.AddOptionInteger("Option1", ref option1);
    go.AddOptionInteger("Option2", ref option2);

    var res = go.GetMultiple(1, 0);

    go.EnableClearObjectsOnEntry(false);
    go.DeselectAllBeforePostSelect = false;
    go.EnablePreSelect(false, true);

    if (res == GetResult.Option)
    {
      integer1 = option1.CurrentValue;
      integer2 = option2.CurrentValue;
      continue;
    }

    if (res != GetResult.Object)
      return Result.Cancel;

    break;
  }

  RhinoApp.WriteLine("Select object count: {0}", go.ObjectCount);
  RhinoApp.WriteLine("Value of integer1: {0}", integer1);
  RhinoApp.WriteLine("Value of integer2: {0}", integer2);

  return Result.Success;
}

– Dale

1 Like

That’s it @dale. Although I did remove a few lines of yours which I assume is a copy & paste error (double enable preselect & addoptioninteger).

Thanks!