GetPoint.Option executes GetPoint.Get when clicking option in commandline

Hi,
GetPoint Loop with options. When clicking on options in commandline, each time a new point is created on the canvas near the commandline. Also, when not using the RhinoApp_EscapeKeyPressed function, a point is created when pressing ESC.

What am i doing wrong?
Thanks :slightly_smiling_face:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
        points.Clear();
        
        while (true)
        {
            m_escape_key_pressed = false;
            RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;
            
            GetPoint getPoint = new GetPoint();
            getPoint.SetCommandPrompt("Please select point");
            
            var boolOptionAxis = new Rhino.Input.Custom.OptionToggle(front, "Front", "Side");
            getPoint.AddOptionToggle("MirrorPlane", ref boolOptionAxis);
            var boolOption = new Rhino.Input.Custom.OptionToggle(clamped, "Off", "On");
            getPoint.AddOptionToggle("Closed", ref boolOption);
            
            if (points.Count > 1)
                getPoint.DynamicDraw += DynDrawCurve;

            getPoint.AcceptNothing(true);
            if (getPoint.Get() == GetResult.Nothing) break;
            if (m_escape_key_pressed) break;

            clamped = boolOption.CurrentValue;
            front = boolOptionAxis.CurrentValue;

            if (front == false)
            {
                xm = -1;
                ym = 1;
            }
            if (front)
            {
                xm = 1;
                ym = -1;
            }

            Point3d pt0 = getPoint.Point();
            Point3d pt0M = new Point3d(xm*pt0.X, ym*pt0.Y, pt0.Z);
            int insert = points.Count / 2;
            points.Insert(insert, pt0);
            points.Insert(insert+1, pt0M);
        }

        NurbsCurve nc = NurbsCurve.Create(clamped, 3, points);

        RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;
        doc.Objects.AddCurve(nc);
        doc.Views.Redraw();

        return Result.Success;
    }

You should check which result is returned by getPoint.Get()

Now you have

if (getPoint.Get() == GetResult.Nothing) break;

but I suggest to use this

GetResult gr = getPoint.Get();
if (gr == GetResult.Nothing) break;
else if (gr == GetResult.Option)
{
//handle options (don't add point)
}
else if (gr == GetResult.Point)
{
//handle point addition (add points here)
}
2 Likes

@menno
:boom::+1:
Thanks a lot!

1 Like