ScriptEditor - Polyline read as PolylineCurve

Hello everyone,

as you can see from the attached example I set the node input as a Polyline:

but after building the project with the ScriptEditor (available for Rhino 8) the node gives me an exception:

Do I miss something?

Best Regards
Luca

Test pline ScriptEditor.gh (6.8 KB)
Test pline ScriptEditor.Components.gha (34.5 KB)

A polyline is more or less a collection of points.

While a PolylineCurve derives from Curve,

you can ToPolyline() to get the underlying polyline from a polylineCurve

please post the code that causes the error.

Curve inputCrv;
Polyline polyline;
//
if (inputCrv is PolylineCurve pCrv)
{
  polyline = pCrv.ToPolyline;
}
else
{
  // error handling
}
//
// alternative 
if (inputCrv.TrygetPolyline(out polyline))
{
  //...
}
// or if you prefere
if (! inputCrv.TrygetPolyline(out polyline))
{
  // error
  return;
}
// ... go on with your logic here
1 Like

Thank you I finally understand.
I set the input as Curve (not as Polyline):

private void RunScript(Curve inputCrv, ref object a)
    {
        Polyline polyLine = new Polyline();
        
        if (inputCrv is PolylineCurve pCrv)
        {
            polyLine = pCrv.ToPolyline();
        }
        
        int npts = polyLine.Count;

        a = npts;
    }

Test pline ScriptEditor_rev.gh (6.1 KB)
Test pline ScriptEditor.Components.gha (35 KB)

without testing - do something like this.
and test it with a non - polyline curve.

private void RunScript(Curve inputCrv, ref object a)
    {
        // defaults and error
        a = null;
        Polyline polyLine = null;
        
        if (inputCrv is PolylineCurve pCrv)
        {
            // success on polyline input
            polyLine = pCrv.ToPolyline();
            int npts = polyLine.Count;
            a = npts;
        }
    }
1 Like