Aligning seams of closed curves?


I’m currently looking for a pythonic way to adjust/align the seams of a collection of closed curves?
Is there a quick way to achieve this?


You mean something like this?

import rhinoscriptsyntax as rs
curves = rs.GetObjects("Select closed curves to align seams of", rs.filter.curve)
guide = rs.GetPointOnCurve(curves[0], "Select optional guide point on first curve")
iterative = rs.GetBoolean("Iterative?", ("Iterative", "Flase", "True"), True)
if(guide == None):
    guide = rs.CurveStartPoint(curves[0])
for curve in curves:
    t = rs.CurveClosestPoint(curve, guide)
    rs.CurveSeam(curve, t)
        guide = rs.EvaluateCurve(curve, t) (501 Bytes)


Thanks for your reply, @Mahdiyar.

Your code inspired me to come up this function:

import Rhino.Geometry as rg

def align_polylines(polylines, guide_idx=None):
    """Aligns closed polylines so that their start/end vertices fall inline.
        If the optional guide index is not defined, the polylines align to 
        the start/end vertex of the first polyline. 
      polylines: A list of closed polylines.
      guide_idx: An optional guide index for the polylines to align to.
      The list of aligned polylines on success, or None."""
    if any([True for p in polylines if not p.IsClosed]):
    if guide_idx == None or guide_idx < 0:
        guide_idx = 0
    elif guide_idx > len(polylines[0]):
        guide_idx = 0
    aligned_polylines = [polylines[guide_idx]]
    for i in range(1, len(polylines)):
        # Get the guide vertex of the previous polyline
        guide_vtx = polylines[i-1][guide_idx]
        # Get the closest index of a vertex of the current polyline
        closest_idx = polylines[i].ClosestIndex(guide_vtx) # -1 on error
        if closest_idx < 0:
        # Get a list of indices of the current polyline
        indices = range(len(polylines[i])-1)
        # Restructure the polyline indices to align them
        align_indices = indices[closest_idx:] + indices[:closest_idx]
        align_vertices = [polylines[i][j] for j in align_indices]
        # Update the guide index
        guide_idx = closest_idx
    return aligned_polylines

One thing to consider (atleast it used to be an issue in r5 when doing this in gh and rhinocommon) when you change the curve seam with Rhinocommon the curves domain gets screwed up (try evaluating the adjusted curve after without reparametrizing). The fix was to first get the curves original domain, then do the seam change, then set the adjusted curves domain back to the original domain.

I’m not sure if this happens also in rhinoscript.