How can I write a script to create a NURBS surface with given control points?
I did find a helpful piece of source code that got me here:
import bpy
surfacedata = bpy.data.curves.new(name='test', type='SURFACE')
surfacedata.dimensions = '3D'
surfacedata.resolution_u = 4
surfacedata.resolution_v = 4
objectdata = bpy.data.objects.new('obj_test', surfacedata)
objectdata.location = (0,0,0)
bpy.context.scene.objects.link(objectdata)
nurbs_surface = surfacedata.splines.new('NURBS')
nurbs_surface.points.add(4)
nurbs_surface.points[0].co = (-1, -1, 0.25, 1)
nurbs_surface.points[1].co = (-1, 1, -0.25, 1)
nurbs_surface.points[2].co = ( 1, -1, -0.25, 1)
nurbs_surface.points[3].co = ( 1, 1, 0.25, 1)
nurbs_surface.order_u = 2
nurbs_surface.order_v = 2
nurbs_surface.use_endpoint_u = True
nurbs_surface.use_endpoint_v = True
However, the object that this produces is just a 1D curve in space,
I can check some of its properties from the python console,
>>> print(len(bpy.data.objects[2].data.splines[0].points))
5
>>> print(bpy.data.objects[2].data.splines[0].point_count_u)
5
>>> print(bpy.data.objects[2].data.splines[0].point_count_v)
1
So, I'm not sure why points has 5 elements (instead of 4), and why point_count_u and point_count_v are 5 and 1 instead of 2 and 2, respectively.
bpy
doesn't (yet) give you access to this control point mesh, in which case, I can't see how you'd do this. $\endgroup$point_count_v
andpoint_count_u
too $\endgroup$