I have a list of points, and want to add a Bezier-spline using these points.

Following is my code:

import bpy

name = "MyCurve"
numPoints = 4
points = [ [1,1,1], [-1,1,1], [-1,-1,1], [1,-1,-1] ]

curvedata = bpy.data.curves.new(name=name,type='CURVE')
curvedata.dimensions = '3D'
curvedata.fill_mode = 'FULL'
curvedata.bevel_depth = 0.045     

ob = bpy.data.objects.new(name+"Obj", curvedata)

polyline = curvedata.splines.new('BEZIER')
for num in range(numPoints):
    polyline.bezier_points[num].co = points[num]
polyline.resolution_u = 1

print( len(polyline.bezier_points))

Now my problem is, that this code adds another point. The printed value will be 5 not as I expected 4. The added point is after the other points and is the point (0, 0, 0). This is unwanted behavior.

What is wrong with my code?

My Blender version is 2.70 built 2014-03-19.


1 Answer 1


A new splines starts with a single point, it is not empty:

import bpy

curvedata = bpy.data.curves.new(name="Curve", type='CURVE')
ob = bpy.data.objects.new("CurveObj", curvedata)

spline = curvedata.splines.new('BEZIER')
# Output: 1

The bezier spline has already a point, so you need to
.add() number of points you want to add minus 1.


By the way - you can assign the coordinates more efficiently like this:

from bpy_extras.io_utils import unpack_list
# ...
polyline.bezier_points.foreach_set("co", unpack_list(points))
  • $\begingroup$ Thanks. Worked perfectly. Do you have a quick reference/tutorial for the suggested assignment method for me? $\endgroup$
    – Dragonseel
    Jun 13, 2014 at 15:45
  • $\begingroup$ foreach_set(): blender.org/documentation/blender_python_api_2_70a_release/… and for unpack_list() see the actual python script in Blender/2.xx/scripts/modules/bpy_extras/io_utils.py. $\endgroup$
    – CodeManX
    Jun 13, 2014 at 16:13

You must log in to answer this question.

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