How determine user don't input anything with GetPoint.Number()

I create a class derived from GetPoint, allow input number with AcceptNumber(true, true), and output number value to command line

public class GetCustomPoint : GetPoint
{
        public GetCustomPoint()
        {
            AcceptNumber(true, true);
            SetCommandPrompt("Get int value");
        }

        protected override void OnDynamicDraw(GetPointDrawEventArgs e)
        {
            base.OnDynamicDraw(e);
            
            double inputNumber = Number();
            RhinoApp.WriteLine(inputNumber.ToString());
        }
}

It works fine except that after deleting previous value, Number() will still return valid value.

  1. output when input 1:
1
1
  1. output when delete 1:
1
1

Thanks

Hi @RyanZhou,

Something to keep in mind is that OnDynamicDraw is called every time the mouse moves. So you’re just printing the same number over and over again, even though the user hasn’t specified a number.

– Dale

Thanks for your explanation and remind.

I want to be notified when input is changed and then draw something dynamically, do you have any suggestion about implementing it?
By the way, OnDynamicDraw will be called after input is changed and mouse not move at the same time.

Hi @RyanZhou,

How about this?

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var number = 3.14159;
  var go = new GetPoint();
  go.SetCommandPrompt("Pick point location");
  go.AcceptNothing(true);
  while (true)
  {
    go.ClearCommandOptions();
    var opt_number = new OptionDouble(number);
    var idx_number = go.AddOptionDouble("Number", ref opt_number);
    var result = go.Get();
    if (result == GetResult.Option)
    {
      var option = go.Option();
      if (idx_number == option.Index)
        number = opt_number.CurrentValue;
      RhinoApp.WriteLine("Number set to {0}", number);
      continue;
    }
    if (result == GetResult.Point)
    {
      doc.Objects.AddPoint(go.Point());
      doc.Views.Redraw();
    }
    if (result != GetResult.Nothing)
      return Result.Cancel;
    break;
  }
  return Result.Success;
}

– Dale

Hi Dale, thanks for your example.

I want to do dynamically drawing before user pressing enter, and your code update view after user pressing enter. The goal is similar with builtin function Circle, when user input new radius without press enter, the circle will be updated with new value.

How about this?

SampleCsCircleRadius.cs

– Dale

@dale, it is not same with builtin command “Circle”, and gets input number after user pressing enter key.

@dale , do you have any other ideas?

Hi @RyanZhou,

Sorry, I don’t understand. How does the Circle command work differently than the above sample?

– Dale

@dale
The difference is that

  1. For Circle command, the circle will be updated/redraw after change the value, no need to press enter
  2. For sample, the circle only be updated/redraw after press enter.
    So Circle command is better for user previewing the result before add circle to document

@dale do you have any suggestion?

Hi @RyanZhou,

Yes I see. This isn’t available to RhinoCommon yet. I’ve logged a wish.

https://mcneel.myjetbrains.com/youtrack/issue/RH-69831

– Dale

Thanks

RH-69831 is fixed in Rhino 7 Service Release 23