5
$\begingroup$

I want to create a curve between two given points. But I don't know how to add the points to the curve object. When you create a new mesh data block, you have the from_pydata() function to add verts, but I can't find an equivalent for the cruve data block. This is my code so far (just creating a new cruve data block and a curve object, then linking it to the collection)

def createCurve():
    star_point = [0,0,0]
    end_point = [1,0,0]
    curve = bpy.data.curves.new(name='curve_data',type='CURVE')
    curveObj = theObj = bpy.data.objects.new("curve_obj", curve)
    bpy.context.collection.objects.link(curveObj)

Can someone help me?

Thanks in advance

$\endgroup$
1
  • $\begingroup$ you want to select the segment between the two points and then subdivide the segment with the the subdivide operator $\endgroup$ Jan 28, 2022 at 15:03

1 Answer 1

6
$\begingroup$

Ok I got it:

polyline = curve.splines.new('POLY')
polyline.points.add(1) 
polyline.points[0].co = start.to_4d()
polyline.points[1].co = end.to_4d()

I don't know why it has to be a vec4 (if you are using bezier splines it's vec3) But it works now

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .