Capture subsequent GetObject calls

Hi,

in my command, I’m asking users to select existing objects from the scene. The selection order is important, so rather than using GetObject.GetMultiple(), I’d like to stack a few GetObject() calls.

The first one works without issues, the second doesn’t trigger, though.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d startPoint;
            using (GetObject go = new GetObject())
            {
                go.SetCommandPrompt("Select start point");
                if (go.Get() != GetResult.Object)
                {
                    RhinoApp.WriteLine("No start point was selected.");
                    return go.CommandResult();
                }
                startPoint = go.Object(0).Point().Location;
            }

            Point3d endPoint;
            using (GetObject go = new GetObject())
            {
                go.SetCommandPrompt("Select end point");
                if (go.Get() != GetResult.Object)
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return go.CommandResult();
                }
                endPoint = go.Object(0).Point().Location;
            }

            doc.Views.Redraw();
            return Result.Success;
        }

Enabling go.OneByOnePostSelect = true; on the second call forces the input prompt, but disables window selection and users now need to click the objects individually.

What am I missing?

Hi @mrhe,

Maybe this?

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go = new GetObject { GeometryFilter = ObjectType.Point };
  go.SetCommandPrompt("Select start point");
  if (go.Get() != GetResult.Object)
    return Result.Cancel;

  var pointObj = go.Object(0).Point();
  if (null == pointObj)
    return Result.Failure;

  var startPoint = pointObj.Location;

  go.SetCommandPrompt("Select end point");
  go.EnablePreSelect(false, true);
  go.DeselectAllBeforePostSelect = false;
  if (go.Get() != GetResult.Object)
    return Result.Cancel;

  pointObj = go.Object(0).Point();
  if (null == pointObj)
    return Result.Failure;

  var endPoint = pointObj.Location;

  RhinoApp.WriteLine("Start point = {0}", startPoint);
  RhinoApp.WriteLine("End point = {0}", endPoint);

  return Result.Success;
}

– Dale

1 Like

Thanks @dale!

Exactly what I needed!