How to draw/preview curves with thickness with C#?


I have a couple points that I want to convert into very conspicuous circles with pink color and a given thickness.

How do I do that in Grasshopper C#?
I read that I could use the DisplayPipeline Class to achieve that…
But how? is there an example?

protected override void SolveInstance(IGH_DataAccess DA)
        {
          // let's say i have a List<Point3d> somepoints 
          // ready for the pink circles.. what's next?
        }

            foreach ( Point3d pt in intersections) {
                Circle cir = new Circle(pt, circlesize);
                args.Display.DrawCurve(cir.ToNurbsCurve(), System.Drawing.Color.DeepPink, thickness);
            }

This is what i did.
attached with an video.
The display is extremely slow. it’s like every time the camera moves, the script recomputes itself again. How to make it faster and more efficient?

You could surely try GhGL

Create your curves once in your SolveInstance routine and reuse them in your drawing routine.

// In your class create a variable to hold onto the curves
List<NurbsCurve> _curves;

// inside of SolveInstance, set the _curves to null
_curves = null;

// inside of your draw routine
if (_curves==null)
{
  _curves = new List<NurbsCurve>();
  foreach(Point3d pt in intersections)
  {
    Circle cir = new Circle(pt, circlesize);
    _curves.Add(cil.ToNurbsCurve());
  }
}

foreach (var curve in _curves)
{
  args.Display.DrawCurve(curve, System.Drawing.Color.DeepPink, thickness);
}

There are display caches on those curves and recreating them from scratch every frame defeats the purpose of having those caches. Just creating curves from circles should only be done once until SolveInstance is called again.

1 Like