How to split a polyline by angle?

I would like to be able to split a closed polyline by a maximum angle threshold, like the SplitAtCorners component in grasshopper. I’ve found the Rhino.Geometry.Polyline.BreakAtAngles method, but I can’t get it to work the way I want it to. The ultimate goal is to convert my grasshopper script into python so I can use it inline with other python scripts I made.

It would help to know how it doesn’t work for you, but here’s a quick implementation example:


230306_BreakAtAngles_00.gh (10.0 KB)

And welcome to the forum of course :slight_smile:

1 Like

Ok, that helps a little, but I’m trying to work in the full on python editor, I’m not in grasshopper anymore. I seem to be getting stuck somewhere in the rhinoscriptsyntax and the Rhino.Geometry. I keep getting “expected Polyline, got guid”

And thanks for the welcome :slight_smile:

I figured it out. for the BreakAtAngles to work it needs to be just geometry. To get that you use rs.coercecurve. To get it back, use scriptcontext.doc.Objects.AddPolyline.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino.Geometry
import math

input = rs.GetObject(“select objects to rebuild”)

curve = rs.coercecurve(input)

polyline = Rhino.Geometry.Curve.TryGetPolyline(curve)

lines = Rhino.Geometry.Polyline.BreakAtAngles(polyline[1], math.radians(130))

i = 0
for i in range(len(lines)):
sc.doc.Objects.AddPolyline(lines[i])

1 Like