Drawing a line from Point to Cursor during GetPoint

Hi there,

I have a c# component to pick two points and try to preview a line during the second GetPoint operation. The line only gets updated when I manipulate the camera and not when I move the mouse.
Maybe I subscribe to the wrong event?

private void RunScript(ref object A)
  {
    Rhino.Input.Custom.GetPoint getPt = new Rhino.Input.Custom.GetPoint();

    getPt.Get();
    basePt = getPt.Point();

    // Preview Line for second GetPoint
    getPt.DynamicDraw += drawMethod;
    getPt.Get();

    display.Dispose();
  }

// <Custom additional code> 
Rhino.Display.CustomDisplay display = new Rhino.Display.CustomDisplay(true);
Point3d basePt = new Point3d();

void drawMethod(object sender, Rhino.Input.Custom.GetPointDrawEventArgs e)
{
  display.Clear();
  display.AddLine(new Line(basePt, e.CurrentPoint), System.Drawing.Color.DodgerBlue, 10);
}

You need to add RhinoDocument.Views.Redraw(); to the your drawMethod:

private void RunScript(ref object A)
{
  var = new Rhino.Input.Custom.GetPoint();
  getPt.Get();
  basePt = getPt.Point();
  getPt.DynamicDraw += drawMethod;
  getPt.Get();
  display.Dispose();
}
// <Custom additional code> 
Rhino.Display.CustomDisplay display = new Rhino.Display.CustomDisplay(true);
Point3d basePt = new Point3d();
void drawMethod(object sender, Rhino.Input.Custom.GetPointDrawEventArgs e)
{
  display.Clear();
  display.AddLine(new Line(basePt, e.CurrentPoint), System.Drawing.Color.DodgerBlue, 10);
  RhinoDocument.Views.Redraw();
}
// </Custom additional code> 

GetPoint.gh (2.2 KB)

Thanks @Mahdiyar! got it to work
How do you format your code like that btw?

1 Like

Surrounding code with three backticks ``` will allow for code to span multiple lines. The code block will try to automatically choose a style for code, but you can explicitly call out the desired formatting.

```cs
function foo(bar)
{
     return bar+1;
}
```
Results in:

function foo(bar)
{
    return bar+1;
}

If you’d ever like to see how someone else created their post you can use the following URL format to view the raw markdown https://discourse.mcneel.com/raw/{topicid}/{postid} take a look at my post as an example.
Read More…

1 Like
Cool, thanks