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?
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;
}
Hello,
I had more or less the same problem of @cristina.b so I updated the code posted by @dale in order to use it with Rhino 6.
These are my updates:
CRhinoCommand::result CCommandSampleSection2::RunCommand(const CRhinoCommandContext& context)
{
CRhinoGetObject go;
go.SetCommandPrompt(L"Select surfaces and polysurfaces");
go.SetGeometryAttributeFilter(CRhinoGetObject::curve_object);
go.EnableGroupSelect(true);
go.EnableSubObjectSelect(false);
go.EnableClearObjectsOnEntry(false);
go.EnableUnselectObjectsOnExit(false);
go.EnableDeselectAllBeforePostSelect(false);
bool objects_were_preselected = false;
while (true)
{
go.GetObjects(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);
int selectedObjectNumber = 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 (int i = 0; i < go.ObjectCount(); i++)
{
const CRhinoObject* rhino_object = go.Object(i).Object();
if (NULL != rhino_object)
rhino_object->Select(false);
}
RhinoApp().ActiveDoc()->Redraw();
}
return result::success;
}
Unfortunately now I’m not able to understand why, if I deselect (maybe accidentally) an objected previously selected, I can’t reselect it.
Do you have any idea about how can I solve this issue?