How do I create a simple curve in python?

I’m trying to create a simple curve in the 2.52 api.
This is what I’ve been able to glean from various places, but it doesn’t work.


c = bpy.context.active_object

it seg faults.


do it in blender and look into console preview
the commands are shown there

hope it helps

happy 2.5

Thanks for the response.
I can partially see how that works. I’m assuming that I’d have to create a ‘PATH’, goto edit mode, select control points and then move/subdivide to get them where I want them. Is that the basic idea?
How do I select control points in python? That’s not showing up in the console.


well beginning to get know how with script
add a list of points to a poly curve

but have an error in script ?
unless you know how to debug this?

i have to wait till tomorrow before debugging this script on IRC

so i hope to have it working tomorrow!
PM me if you want the buggy script! LOL

happy 2.5

1 Like

Try this

import bpy

def makeSpline(cu, typ, points):
    spline =
    npoints = len(points)
    if typ == 'BEZIER' or typ == 'BSPLINE':
        for (n,pt) in enumerate(points):
            bez = spline.bezier_points[n]
            (, bez.handle1, bez.handle1_type, bez.handle2, bez.handle2_type) = pt
        spline.points.add(npoints-1)    # One point already exists?
        for (n,pt) in enumerate(points):
            spline.points[n].co = pt
cu ="MyCurve", "CURVE")
ob ="MyCurveObject", cu)
scn = bpy.context.scene = ob

cu.dimensions = "3D"

makeSpline(cu, "NURBS", [(0,0,0,1), (0,0,1,1), (0,1,1,1), (1,4,1,1)] )
makeSpline(cu, "NURBS", [(1,0,0,1), (1,0,1,1), (1,2,1,1), (1,4,1,1)] )
makeSpline(cu, "NURBS", [(2,1,0,1), (2,1,1,1), (2,3,1,1), (1,4,1,1)] )

any good doc showing how to use the new instructions in 2.5 for curves?

need the one for setting close / open curve

and defresol also!

any idea how to set theses ?


I just use the API documentation for bpy.types.Curve and below, in particular bpy.types.Spline

“new()” method is not available in in blender 2.5.2.

cu =“MyCurve”, “CURVE”)

any suggestions?

#4 example runs on a just compiled Blender (17-5-2010 8:15) SVN 28800