import bpy
name = "wiggle"
curve = bpy.data.curves.new(name, 'CURVE')
curve.dimensions = '3D'
# only if you need some non-zero Z coordinates
spline = curve.splines.new('BEZIER')
# options are 'POLY', 'BEZIER', 'BSPLINE', 'CARDINAL', 'NURBS'
# the spline starts off with a single point, we want one more.
spline.bezier_points.add(1)
b0 = spline.bezier_points[0]
b1 = spline.bezier_points[1]
b0.handle_left = (-2.5, -0.5, 0)
b0.co = (-2, 0, 0)
b0.handle_right = (-1, 1, 0)
b1.handle_left = (1, -1, 0)
b1.co = (2, 0, 0)
b1.handle_right = (2.5, 0.5, 0)
# curves data can have multiple unconnected curves
s2 = curve.splines.new('BEZIER')
# we want 3 = 1+2
s2.bezier_points.add(2)
b0 = s2.bezier_points[0]
b1 = s2.bezier_points[1]
b2 = s2.bezier_points[2]
b0.handle_left = (-0.5, 2.5, 1)
b0.co = (0, 2, 1)
b0.handle_right = (1, 1, 1)
b1.handle_left = (1, 1, 1)
b1.co = (0, 0, 1)
b1.handle_right = (-1, -1, 1)
b2.handle_left = (-1, -1, 1)
b2.co = (0, -2, 1)
b2.handle_right = (0.5, -2.5, 1)
#
s3 = curve.splines.new('BEZIER')
s3.bezier_points.add(1)
b0 = s3.bezier_points[0]
b1 = s3.bezier_points[1]
b0.handle_left = (-1, 1, -1)
b0.co = (0, 1, -1)
b0.handle_right = (1, 1, -1)
b1.handle_left = (1, -1, -1)
b1.co = (0, -1, -1)
b1.handle_right = (-1, -1, -1)
s3.use_cyclic_u = True
# forms a closed loop
#
#
ob = bpy.data.objects.new(name, curve)
scn = bpy.context.scene
scn.objects.link(ob)
ob.select = True
for i in range(len(curve.splines)):
spline = curve.splines[i]
print("spline[%d]" % i)
for j in range(len(spline.bezier_points)):
bp = spline.bezier_points[j]
print("bp[%d] = %s(%s , %s , %s)%s" % (j, bp.handle_left_type, bp.handle_left, bp.co, bp.handle_right, bp.handle_right_type))
|
Blender python API quick-start
Syntax highlighting by Pygments.