RuntimeError: 3 : Break is not available for this segment point

RuntimeError: 3 : Break is not available for this segment point

burns215
Explorer Explorer
1,188 Views
4 Replies
Message 1 of 5

RuntimeError: 3 : Break is not available for this segment point

burns215
Explorer
Explorer

burns1_0-1722892524467.png

 

 

I am trying to break a spline in multiple places, but I keep getting this error. I am fairly certain that the point is on the spline (I've printed the coordinates), and I've tried to identify the break point in different ways (intersection with plane and also curveEval as shown in my code here). All components are in the same sketch. I have a sketch point and a 3d object point where the break should happen. I have an intersecting curve. I'm not sure why it's unable to break at this point (or any of my later break points), and I can't find any documentation about this issue online. Thank you in advance for the help! I have attached the code as a txt file and the spline points csv file. I have the csv file in a folder, which the program uses to make the spline I am trying to break.

0 Likes
Accepted solutions (1)
1,189 Views
4 Replies
Replies (4)
Message 2 of 5

Jorge_Jaramillo
Collaborator
Collaborator
It fails to open a file which is missing to test your code:
FileNotFoundError: [Errno 2] No such file or directory: 'C:/points/bedandapex_picked_points.pp'
0 Likes
Message 3 of 5

burns215
Explorer
Explorer

Sorry, I forgot to add that file. But that file isn't directly relevant to the error that I'm getting anyway, so I updated the code text file so that it no longer uses that file.

0 Likes
Message 4 of 5

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

The problem comes from the fact that the intersection point of the the two curves (spline1 and 

bottomlengthspline) can NOT be the point given to the breakCurve() method.  It is not explained in the documentation but looks to be that.
 
I was able to split it with the following two changes in you code (as for the first breakCurve() call):

 

        # (...)

        spline1_mid_point = xfind_closest_point_on_spline(spline1, midpoint_x, ui)
        app.log(f'{spline1_mid_point.asArray()=}')
        #=====================================================================
        # CHANGE #1. choose the spline1's mid fit-point like so:
        #=====================================================================
        spline1_mid_fitpoint = spline1.fitPoints[spline1.fitPoints.count // 2].geometry
        app.log(f'{spline1_mid_fitpoint.asArray()=}')

        # Get sketch points
        sketchPoints = sketch.sketchPoints
        
        sketchPoint = sketchPoints.add(spline1_mid_point)


        apex_height = .03

        # Create an ObjectCollection for the spline points
        bottomlengthsplinefitPoints = adsk.core.ObjectCollection.create()

        # Add points to the ObjectCollection with correct z-coordinates
        bottomlengthsplinefitPoints.add(adsk.core.Point3D.create(spline1_mid_point.x, spline1_mid_point.y, spline1_mid_point.z))
        bottomlengthsplinefitPoints.add(adsk.core.Point3D.create(spline1_mid_point.x, .35954113, .54831595 + apex_height))
        bottomlengthsplinefitPoints.add(adsk.core.Point3D.create(spline1_mid_point.x, first_point.y + .7, spline1_mid_point.z-.075))

        # Create the spline that passes through the points in the ObjectCollection
        bottomlengthspline = sketch.sketchCurves.sketchFittedSplines.add(bottomlengthsplinefitPoints)

        #Break curve at midpoint 
        #=====================================================================
        #CHAGE #2. provinding spline1_mid_fitpoint to the breakCurve() like so:
        #=====================================================================
        bottom_split_result = spline1.breakCurve(spline1_mid_fitpoint, True)
        bottomcurve1, bottomcurve2 = bottom_split_result
        app.log(f'{sketch.sketchCurves.sketchFittedSplines.count = }')

        # (...)

 

 

And this is the result:

Jorge_Jaramillo_0-1722901706955.png

 

Then you script fails again in the following call to breakCurve().  You have to make the changes on those too.

 

Regards,

Jorge Jaramillo

 

Message 5 of 5

burns215
Explorer
Explorer

That fixed it, thank you so much! For the later breaks, I changed my earlier function to keep track of a close point on the spline to the point i want to break. 

def find_closest_point_on_spline(curve, y_value, ui):
    try:
        curveEval = curve.geometry.evaluator
        (_, parameter_start, parameter_end) = curveEval.getParameterExtents()

        # Define the precision for the parameter search
        step = 0.0001
        min_distance = float('inf')
        closest_point = None
        closest_param = None
        prev_point = None
        
        # Iterate over the spline with defined step size
        param = parameter_start
        while param <= parameter_end:
            # Calculate the point on the curve
            (_, point) = curveEval.getPointAtParameter(param)
            
            # Calculate the distance to the desired y value
            distance = abs(point.y - y_value)
            
            # Update the closest point if this one is closer
            if distance < min_distance:
                min_distance = distance
                closest_point = point
                closest_param = param
                
            # Increment parameter
            param += step
            
            # If we have found the closest point, set the previous point
            if param >= closest_param + step:
                prev_point = point

        return closest_point, prev_point
    
    except Exception as e:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
        return None, None