AddPolyline

How do you add a Polyline to Rhino even if it is not valid?
Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(polyline)

What I specifically refer to are polylines with duplicates points, I need to keep it like that on purpose.

An example would be helpful. I am reading “I have invalid polylines and I like them. How do I make Rhino document like my invalid polylines too!” :sweat_smile:

1 Like

For example

#! python 3
import Rhino
from Rhino.Geometry import Polyline, Point3d

p0 = Point3d(0, 0, 0)
p1 = Point3d(0, 0, 0)
p2 = Point3d(0, 2, 0)
polyline = Polyline([p0, p1, p2])
Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(polyline)

Okay so the official answer is zero-length segments are considered invalid in Polylines. You can use the document tolerance to put the points super-close so the distance is not zero

y = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance
p0 = Point3d(0, 0, 0)
p1 = Point3d(0, y, 0)
p2 = Point3d(0, 2, 0)
polyline = Polyline([p0, p1, p2])

Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(polyline)

McNeel made some secret agreements for zero-length polylines :slight_smile:
Why does it work when polyline.ToNurbsCurve() is called? It callapses the short segments?

Stacked control points in NurbsCurve are valid but discouraged. If you convert an invalid polyline with stacked points to a nurbs, you will get a valid degree 1 nurbs curve with stacked ‘control’ points. see the IsValid and degree is debugger view:

Polyline Invalid

Nurbs Valid

You can convert the polyline to nurbs and add that to document: (:warning: discouraged)

c = polyline.ToNurbsCurve()
Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(c)

ScriptEditor is awesome!
It is really nice that you can debug this directly in Rhino. Thank you.

1 Like

One thought here:
Would it be a good idea to take the points of the polyline, cull duplicates and rebuild the polyline before “baking” it?

Yup, but I really need to keep those duplicates points :slight_smile:

For stuff like lofting triangular faces:

2 Likes

Oh I see so it allows you to loft a ‘single’ point to an edge. Very nice