In blender i want to cut a curve with a specific distance (for example as much as a cylinder's radius). I can do it by hand but can't do with python scripts. I tried converting it into a mesh object and place a uv sphere on it and add boolean function with intersect operation, but it still didn't work. I also tried to extrude it and again with uv sphere apply boolean function, but couldn't make it a single line(after extruding it and converting into a mesh then after boolean back to a curve object, i get 4 lines, but i want to get a smaller curve than my initial).

def create_bezier_curve(name:str, coordinates: list[tuple[int, int, int]]):
    A function for creating a bezier curve with a specific name from assigned coordinates. </br> 
    `name`: the name/id assigned to the curve
    `coordinates`: Coordinates of the points that are going to form the curve. Example: [(0,1,2),(4,5,6)]
    # Create a curve data block and a curve object
    curve_data = bpy.data.curves.new(name, 'CURVE')
    curve_obj = bpy.data.objects.new(name, curve_data)

    # Set the curve dimensions to 3D
    curve_data.dimensions = '3D'

    # Add a BEZIER spline to the curve
    spline = curve_data.splines.new('BEZIER')

    # Add points to the spline
    spline.bezier_points.add(len(coordinates) - 1)  # Subtract one because of the default point at the origin

    # Assign the coordinates to the points
    for i, coord in enumerate(coordinates):
            x, y, z = coord
            spline.bezier_points[i].co = (x, y, z)
            spline.bezier_points[i].handle_left_type = 'AUTO'
            spline.bezier_points[i].handle_right_type = 'AUTO'

    # Link the curve object to the scene

    return curve_obj

# Example usage
coordinates = [(4, 0, 0), (3, 0, 0), (2, 0, 0), (1, 0, 0), (0, -0.5, 0.5),(-1, -1, 2), \
                (-1.5,-1.5 , 3)]
curve_name = 'Curve'
curve = create_bezier_curve(curve_name, coordinates)

this is my code creating a curve from points. What can i change to get a shorter curve? Or is there any way to cut this one? Thank you in advance.



You must log in to answer this question.

Browse other questions tagged .