C++ Retrieve two curve - simple question

Hi,

In Rhino Plugin C++ I just want to retrieve two curves by separate commands.

I simply write the code below, but when I run it only first curve is selected but not a second command is not executed (neither I can select second curve nor I see the text “Select second curve”).
What I am missing?
In command line I see only Select first curve and no text Select second curve

What I write below as code is not right…

	CRhinoGetObject gc0;
	gc0.SetCommandPrompt(L"Select first curve");
	gc0.SetGeometryFilter(CRhinoGetObject::closed_curve);
	gc0.GetObjects(1, 1);
	if (gc0.CommandResult() != success)
		return gc0.CommandResult();
	const CRhinoObjRef& obj_ref0 = gc0.Object(0);
	const ON_Curve* crv0 = obj_ref0.Curve();
	if (crv0 == 0)
		return failure;

	CRhinoGetObject gc1;
	gc1.SetCommandPrompt(L"Select second curve");
	gc1.SetGeometryFilter(CRhinoGetObject::closed_curve);
	gc1.GetObjects(1, 1);
	if (gc1.CommandResult() != success)
		return gc1.CommandResult();
	const CRhinoObjRef& obj_ref1 = gc1.Object(0);
	const ON_Curve* crv1 = obj_ref1.Curve();
	if (crv1 == 0)
		return failure;

More simply can someone give an example how to retrieve two curves in separate commands?

Hi @Petras_Vestartas,

Try this:

CRhinoGetObject go0;
go0.SetCommandPrompt(L"Select first stuff");
go0.GetObjects(1, 0);
if (go0.CommandResult() != CRhinoCommand::success)
  return go0.CommandResult();

CRhinoGetObject go1;
go1.SetCommandPrompt(L"Select second stuff");
go1.EnablePreSelect(FALSE, TRUE);
go1.EnableDeselectAllBeforePostSelect(false);
go1.GetObjects(1, 0);
if (go1.CommandResult() != CRhinoCommand::success)
  return go1.CommandResult();

– Dale

Thank you Dale.

These two lines makes the difference:
go1.EnablePreSelect(FALSE, TRUE);
go1.EnableDeselectAllBeforePostSelect(false);

Could you explain why it has to be done this way?
I noticed that it must be included for the same type of objects.
If I retrieve curve then surface for instance it works good, but if I want to get curve and then again curve I have to add these two lines of code.

Well, the call to EnablePreSelect(FALSE) is required because otherwise the objects selected by the first getter(which are now pre-selected) will be be selected by the second getter.

The EnableDeselectAllBeforePostSelect(false) is used to prevent pre-selected objects from being deselected, this indicating to the user they are already selected.

– Dale

1 Like

Thank you.

In rhino i see what happens it deselects previous curve and select the second one.

Is there any situation when user would like to retrieve already selected objects?
I am wondering why these two lines are not set as default behaviour.