Draw line from curve

Hi there,
I’m wondering if there’s a way to do something similar to the GetPoint.DrawLineFromPoint() function but instead of dynamically drawing from a point, it could dynamically draw from a curve with one end constrained to the curve (snapping to the closest point on the curve) and the other end following the mouse. Thanks in advance!

Hi @Sophie3,

below is a Python example which you might replicate using Rhino Common.

GetPointDrawLine.py (1.4 KB)

_
c.

1 Like

Thank you @clement - that was very helpful!

Here is the C# version in case anyone is interested:

  public class MyGetPoint : Rhino.Input.Custom.GetPoint
  {
      public Curve curve {   get; set; }
      public Line line { get; set; }

      public Point3d startPoint { get; set; }

      protected override void OnDynamicDraw(GetPointDrawEventArgs e)
      {
          double t;
          bool success = curve.ClosestPoint(e.CurrentPoint, out t);
          if (!success) return;

          startPoint = curve.PointAt(t);
          line = new Line(startPoint, e.CurrentPoint);
          e.Display.DrawLine(line, System.Drawing.Color.Black, 2);
          base.OnDynamicDraw(e);
      }
  }

  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
      var go = new GetObject();
      go.SetCommandPrompt("Select Curve");
      go.GeometryFilter = ObjectType.Curve;
      go.GetMultiple(1, 1);

      
      if (go.CommandResult() != Result.Success)
          return go.CommandResult();
      
      MyGetPoint myGetPoint = new MyGetPoint();
      myGetPoint.curve = go.Object(0).Curve();
      myGetPoint.SetCommandPrompt("pick a point");
      //myGetPoint.DrawLineFromPoint(myGetPoint.startPoint, false);
      myGetPoint.Get();

      if (myGetPoint.line.IsValid)
      {
          doc.Objects.AddLine(myGetPoint.line);
          doc.Views.Redraw();
      }

      return Result.Success;
  }
1 Like