Programmatically stop object selection

Hello,

I’d like to know if it is possible to stop object selection when using CRhinoGetObject. I mean, I know that to ask the user selecting an object I can use the following code:

CRhinoGetObject gc;
gc.SetCommandPrompt(L"Select Part to be deposed");
gc.SetGeometryFilter(CRhinoGetObject::mesh_object);
//gc.SetGeometryAttributeFilter(CRhinoGetObject::open_curve);
gc.EnableDeselectAllBeforePostSelect(false);
gc.GetObjects(1, 1);
if (gc.ObjectCount() != 1)
{
	// Nothing selected or too many object selected -> Error
	return 1;
}

However, I’d like to know how I could stop asking for section programmtaitcally. I’m asking this since I have an user interface where I have a button that must be clicked to select geometry, but I need also to give the possibility to stop selection (since I do not know how many objects the user will select and I’d like not to need pressing esc to stop selection). Thank you for your attention!

You can control how many object the user can or must select by passing the required values to CRhinoGetObject::GetObject.

For example, if the user must pick 4 objects, you’d do this:

int minimum_number = 4;
int maximum_number = 4;
gc.GetObjects(minimum_number, maximum_number);

Does this help?

– Dale

Thnk you for your answer Dale. Unfortunately that’s not what I was looking for. I’d like to start the selection with GetObjects set for example to 10000 as maximum number, to be sure the user can select a lot of objects. But I want to give the user the possibility to select as many objects as he likes and then stop the selection proessing a button (instead of esc or enter), for this reason I was wondering if there’s a way to stop the selection not pressing esc (or reaching the maximum limit of allowed objects) but pressing a button in a gui. Hope I’m clear, I can provide more details if needed

You can always have a button that runs RhinoApp.RunScript("_Enter", false); when clicked. That will effectively press Enter and end the currently active GetObjects.

Hi @g_v_c,

Something like this might work:

void CMyCancelButton::OnLButtonDown(UINT nFlags, CPoint point)
{
  CRhinoDoc* pDoc = RhinoApp().ActiveDoc();
  if (pDoc && pDoc->InGetObject())
    pDoc->RunScript(L"!", 0);
}

A more advanced way is to register a custom window message using Win32’s RegisterWindowMessage function. Then call CRhinoGetObject::AcceptCustomWindowsMessage and pass your custom window message. Your dialog box cancel button hander, when pressed would post the custom window message, which would be caught by your object getter.

CRhinoGet::PostCustomWindowsMessage(SampleModelessCancelPlugIn().WindowMessage(), 0, 0); 

See this sample project for details.

SampleModelessCancel

– Dale