Splitting a closed curve in two places not at start/end

Hi all,

I can’t figure out how to do this in Python/Rhinocommon - I have a closed 4 segment curve which I need to split in two places, neither of which is the curve start/end point. I can use ClosestPoint() to get the curve params and then use Curve.Split(params) to split the curve, but I end up with 3 segments… Is there an easy way to get the segments around the start/end point to join back together? (The normal Rhino Split(Point) command does this). I tried jumping through a few hoops, but nothing works reliably, must be missing something obvious here…

Thanks, --Mitch

Hi Mitch,

Shooting from the hip, not testing any real code:
If more than 2 curves are returned, test curve start-end point for being equal to either split points.
All curves with end-starts points not at either split points are joined together.


Yeah, that should work, thanks - still rather painful though… :neutral_face: --Mitch

Before splitting, the Rhino command checks if the curve is closed, and, if so, it moves the seam to the first splitting parameter point.

Hi Mitch,

this seems to work too:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    crv_id = rs.GetObject("Closed curve", 4, True, False)
    if not crv_id: return
    if not rs.IsCurveClosed(crv_id): return
    pt0 = rs.GetPointOnCurve(crv_id, "First split point on curve")
    if not pt0: return
    pt1 = rs.GetPointOnCurve(crv_id, "Second split point on curve")
    if not pt1: return
    crv = rs.coercecurve(crv_id, -1, True)
    rc0, param0 = crv.ClosestPoint(pt0)
    rc1, param1 = crv.ClosestPoint(pt1)
    if param0 == param1: return
    c0 = crv.Trim(param0, param1)
    c1 = crv.Trim(param1, param0)
    scriptcontext.doc.Objects.Delete(crv_id, False)



Yeah, that is what I tried first, but I didn’t get it to work - now I see I probably used the wrong method, instead of using ChangeClosedCurveSeam(), I tries SetStartPoint()…

Thanks! --Mitch