Select or create a polyline from the command line

Hi,
I want to either select a polyline or create one from the command line. I managed to select one with Input.Custom.GetObject() or create one with Input.Custom.GetPolyline(), but I’m not sure if I can get from one command to the other.

I want to create an option in the selection command to jump to the creation command. Is this possible? If so, how?

Thanks in advance.

Hi @Not_Necessarily,

Something to try:

public class TestPolyline : Command
{
  public override string EnglishName => "TestPolyline";

  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
    var go = new GetPolylineObject();
    go.SetCommandPrompt("Select polyline");
    go.AddOption("Create");
    var result = go.Get();
    if (result == GetResult.Option)
      return GetPolyline(doc, mode);
    if (result != GetResult.Object)
      return Result.Cancel;

    var objref = go.Object(0);
    var curve = objref.Curve();
    if (null == curve)
      return Result.Failure;

    if (curve.TryGetPolyline(out var polyline))
      RhinoApp.WriteLine("Polyline wth {0} points selected.", polyline.Count);

    return Result.Success;
  }

  private Result GetPolyline(RhinoDoc doc, RunMode mode)
  {
    var gp = new GetPolyline();
    var rc = gp.Get(out var polyline);
    if (rc == Result.Success)
    {
      doc.Objects.AddPolyline(polyline);
      RhinoApp.WriteLine("Polyline wth {0} points created.", polyline.Count);
      doc.Views.Redraw();
    }
    return rc;
  }
}

internal class GetPolylineObject : GetObject
{
  public override bool CustomGeometryFilter(RhinoObject obj, GeometryBase geom, ComponentIndex ci)
  {
    if (geom is Curve curve)
    {
      if (curve.TryGetPolyline(out var polyline))
        return true;
    }
    return false;
  }
}

– Dale

1 Like

Thanks. Works great. I was unaware of GetResult.Option.