Scripting help, Split curves and move

I just starting to learn how to script, i think i’ve gotten as far as i can go on this with a little help from chatgpt. So far i’m getting a selection then splitting it with another selected curve. Id like help figuring out how to move part of my selection after its been split based off of the curve that was used to get the split points and its orientation.


FlatSeam.py (1.2 KB)
SeamSplit.3dm (3.0 MB)

If you collect the return values of SplitCurve, you can sort the other components into two groups based on which partial perimeter curve they’re closest to. For the move direction, you can define a plane based on the seam line start and end points and get a perpendicular vector that way.

start = rs.CurveStartPoint(flat_seam_line)
end = rs.CurveEndPoint(flat_seam_line)
plane = rs.PlaneFromPoints(start, end, start + rs.WorldXYPlane().ZAxis)
distance = 10
move_vector = distance*plane.ZAxis
1 Like

Thanks ill give it a try.

How would you filter through the return values of rs.SplitCurve to determine which side of the plane they are on.

When you split your boundary curve, rs.SplitCurve returns a list of the pieces. You can use CurveClosestObject with each of the other curves like this:

perimeter_curve = # whatever
other_curves = # whatever

split_pieces = rs.SplitCurve(perimeter_curve, splitting_curve)

side1, side2 = split_pieces
side1_pieces = []
side2_pieces = []

for curve in other_curves:
    id = rs.CurveClosestObject(curve, split_pieces)[0]
    if id == side1:
        side1_pieces.append(curve)
    else: # id == side2
        side2_pieces.append(curve)

rs.MoveObjects([side1] + side1_pieces, move_vector)

Thank you for the help, ive got it to move one line of the split curve but the other curves are staying stationary. I hope implemented this correctly

import rhinoscriptsyntax as rs

def FlatSeam():

    # Select the panel and everything in it that needs a flat seam
    inital_selection = rs.GetObjects("Select the panel you want to Flat Seam", preselect=True)
    if not inital_selection:
        print("No curve selected.")
        
        
    # Select the curve where you want the flat seam to be made
    flat_seam_line = rs.GetObject("Select the Flat Seam line", filter=4)
    if not flat_seam_line:
        print("No curve selected")
        
    split_param = []
    for panelcrv in inital_selection:
        if not rs.IsCurve(panelcrv):
            continue
            
        intersection_list = rs.CurveCurveIntersection(panelcrv, flat_seam_line)
        if not intersection_list:
            continue
            
        for intersections in intersection_list:
            if intersections[0] == 1:
                split_param.append(intersections[5])
                        
        # Split the curves that touch the selected flat seam curve
        if split_param:
            split_param = sorted(set(split_param))
            split_curves = rs.SplitCurve(panelcrv, split_param)
            side1, side2 = split_curves
            side1_pieces = []
            side2_pieces = []
            
            other_curves = rs.GetObjects("Select other curves")
            
            for curve in other_curves:
                id = rs.CurveClosestObject(curve, split_curves[0])
                if id == side1:
                    side1_pieces.append(curve)
                else: # id == side2
                    side2_pieces.append(curve)
            
    # Plane referenced for moving objects 
    if rs.IsCurve(flat_seam_line):
        start = rs.CurveStartPoint(flat_seam_line)
        rs.AddPoint(start)
        end = rs.CurveEndPoint(flat_seam_line)
        rs.AddPoint(end)
        
        length = rs.Distance(start, end)
        
        #Add plane just for visualization  
        plane = rs.PlaneFromPoints(start, end, start + rs.WorldXYPlane().ZAxis)
        rs.AddPlaneSurface(plane, length, length)
        
    # Move the objects from inital_selection after getting split
    distance = -5
    move_vector = distance * plane.ZAxis

    rs.MoveObjects([side1] + side1_pieces, move_vector)

FlatSeam()