Can I add new a BezierSplinePoint to the start and end of a given curve in python. I'm thinking something like this:

curve = bpy.context.active_object # Some given curve with a disired shape

bpy.ops.curve.subdivide(number_cuts = N) # It now has +N point which DOESN'T alter the original shape. I need this.

### The rest is only pseudo-code
start_point = BezierSplinePoint(start_coordinates?) # I don't know how to create custom points
end_point   = BezierSplinePoint(start_coordinates?) # I don't know how to create custom points

curve.data.splines[0].bezier_points.add_point_at_index(start_point, index=0) # How to add thise point to the collection
curve.data.splines[0].bezier_points.add_point_at_index(end_point, index=N+1) # How to add thise point to the collection 

EDIT: This post Poly / Bezier curve from a list of coordinates does pretty much what I want, but it starts the curve from scratch, where as I have most of the points already

EDIT2: This is driving me crazy! I figured that I could add points like so:

# curve is the object I try to manipulate 
bp = curve.data.splines[0].bezier_points

and then loop over all the points and move their index up by one, and then set the two outer verteces with:

curve.data.splines[0].bezier_points[0].co           = (1,2,3)
curve.data.splines[0].bezier_points[0].handle_right = (4,5,6)
curve.data.splines[0].bezier_points[0].handle_left  = (7,8,9)

This is quite frustrating considering that python usually is very generous with regards to array and list manipulation. But I can't get this to work either! Aren't the points ordered in the collection like they are connected along the curve?

  • 1
    $\begingroup$ without checking your script, you should use: point.co = Vector((x,y,z)), it's safer. As for a solution, is using the points and the method described in the other post and recreate the entire curve? Use the existing points as a list, add the ones you want and create a new curve object from that list? I can understand if that's too much of a hack for you, but it might just work. $\endgroup$ Dec 4 '20 at 11:30
  • $\begingroup$ @FrederikSteinmetz concur. Would use the numpy method indicated in one of the links to blender.stackexchange.com/questions/203965/… $\endgroup$
    – batFINGER
    Dec 4 '20 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.