here a script for bezier curve from the code snippet PDF file as example
#----------------------------------------------------------
# File curve.py
#----------------------------------------------------------
import bpy
def createBevelObject():
# Create Bevel curve and object
cu = bpy.data.curves.new('BevelCurve', 'CURVE')
ob = bpy.data.objects.new('BevelObject', cu)
bpy.context.scene.objects.link(ob)
# Set some attributes
cu.dimensions = '2D'
cu.resolution_u = 6
cu.twist_mode = 'MINIMUM'
ob.show_name = True
# Control point coordinates
coords = [
(0.00,0.08,0.00,1.00),
(-0.20,0.08,0.00,0.35),
(-0.20,0.19,0.00,1.00),
(-0.20,0.39,0.00,0.35),
(0.00,0.26,0.00,1.00),
(0.20,0.39,0.00,0.35),
(0.20,0.19,0.00,1.00),
(0.20,0.08,0.00,0.35)
]
# Create spline and set control points
spline = cu.splines.new('NURBS')
nPointsU = len(coords)
spline.points.add(nPointsU)
for n in range(nPointsU):
spline.points[n].co = coords[n]
# Set spline attributes. Points probably need to exist here.
spline.use_cyclic_u = True
spline.resolution_u = 6
spline.order_u = 3
return ob
def createCurveObject(bevob):
# Create curve and object
cu = bpy.data.curves.new('MyCurve', 'CURVE')
ob = bpy.data.objects.new('MyCurveObject', cu)
bpy.context.scene.objects.link(ob)
# Set some attributes
cu.bevel_object = bevob
cu.dimensions = '3D'
cu.use_fill_back = True
cu.use_fill_front = True
ob.show_name = True
# Bezier coordinates
beziers = [
((-1.44,0.20,0.00), (-1.86,-0.51,-0.36), (-1.10,0.75,0.28)),
((0.42,0.13,-0.03), (-0.21,-0.04,-0.27), (1.05,0.29,0.21)),
((1.20,0.75,0.78), (0.52,1.36,1.19), (2.76,-0.63,-0.14))
]
# Create spline and set Bezier control points
spline = cu.splines.new('BEZIER')
nPointsU = len(beziers)
spline.bezier_points.add(nPointsU)
for n in range(nPointsU):
bpt = spline.bezier_points[n]
(bpt.co, bpt.handle_left, bpt.handle_right) = beziers[n]
return ob
def run(origin):
bevob = createBevelObject()
bevob.location = origin
curveob = createCurveObject(bevob)
curveob.location = origin
bevob.select = False
curveob.select = True
bpy.ops.transform.translate(value=(2,0,0))
return
if __name__ == "__main__":
run((0,0,0))
you can upload in text editor and run it then look into the viewport
it looks that there is an error on this script
you can remove the fill back line i guess
and there is also a bevel curve added to the curve which you don’t really need
hope it helps
salutations