How do I create a simple curve in python?

Hi,
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.

bpy.ops.object.curve_add()
bpy.ops.object.editmode_toggle()

c = bpy.context.active_object
bpy.ops.curve.vertex_add(location=(0,0,0))

it seg faults.

Thanks,
Dave

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.

Thanks!
-dave

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 = cu.splines.new(typ)
    npoints = len(points)
    
    if typ == 'BEZIER' or typ == 'BSPLINE':
        spline.bezier_points.add(npoints-1)
        for (n,pt) in enumerate(points):
            bez = spline.bezier_points[n]
            (bez.co, bez.handle1, bez.handle1_type, bez.handle2, bez.handle2_type) = pt
    else:
        spline.points.add(npoints-1)    # One point already exists?
        for (n,pt) in enumerate(points):
            spline.points[n].co = pt
        
    return
    
cu = bpy.data.curves.new("MyCurve", "CURVE")
ob = bpy.data.objects.new("MyCurveObject", cu)
scn = bpy.context.scene
scn.objects.link(ob)
scn.objects.active = 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 ?

Thanks

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

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

cu = bpy.data.curves.new(“MyCurve”, “CURVE”)

any suggestions?

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