Select more objects to an existing list - Rhino Common


#1

Hi,
We have a list of objects which we highlight(select in code).
We need to be able to let the user pick new objects without unselecting these objects.
The user should be able to select/unselect every object (both old and newly selected).
The selection process should end when the user presses ‘Enter’ or in a similar manner.
Do you have any suggestions how to accomplish this?

Thank you!


(Dale Fugier) #2

Hi Cristina,

I think this is what you are looking for. Let me know if it isn’t.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go = new GetObject();
  go.SetCommandPrompt("Select surfaces and polysurfaces");
  go.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter;
  go.GroupSelect = true;
  go.SubObjectSelect = false;
  go.EnableClearObjectsOnEntry(false);
  go.EnableUnselectObjectsOnExit(false);
  go.DeselectAllBeforePostSelect = false;

  var objects_were_preselected = false;
  while (true)
  {
    go.GetMultiple(1, 0);
    if (go.CommandResult() != Result.Success)
      return go.CommandResult();

    if (go.ObjectsWerePreselected)
    {
      objects_were_preselected = true;
      go.EnablePreSelect(false, true);
      continue;
    }

    break;
  }

  // TODO: process selected objects here
  RhinoApp.WriteLine("Object selected count = {0}", go.ObjectCount);

  if (objects_were_preselected)
  {
    // Normally, pre-selected objects will remain selected, when a
    // command finishes, and post-selected objects will be unselected.
    // This this way of picking, it is possible to have a combination
    // of pre-selected and post-selected. So, to make sure everything
    // "looks the same", lets unselect everything before finishing
    // the command.
    for (var i = 0; i < go.ObjectCount; i++)
    {
      var rhino_object = go.Object(i).Object();
      if (null != rhino_object)
        rhino_object.Select(false);
    }
    doc.Views.Redraw();
  }

  return Result.Success;
}

– Dale


#3

Hi,

Thank you very much for your help!
We managed to use your code in our method.

Thank you!

Cristina