Blender’s Python console automatically does this every time you start Blender:
C = bpy.context
D = bpy.data
And probably a little more than that, too.
C.object.data.splines.order_u says to Blender, roughly : “for the object that’s currently selected, poke around in its data, find the sixteenth spline and tell me what it’s order_u property is” So naturally this won’t work if you haven’t got sixteen splines.
for spline in bpy.context.active_object.data.splines: spline.order_u = spline.order_u + 1 is really close to right. I think you just forgot to
import bpy and of course you should have an indent between the
: and the
I enclosed it in a try/except block, because it’s not a safe bet that there actually is a property called
order_u (Bezier splines), let alone
data. If the object selected is an empty, it doesn’t have any data associated with it, it’s just the object. The
data can be a mesh, a curve, a lattice, an armature, any kind of data-block that can exist in 3D space as an object. Only curves have splines, so I use a try/except block when I don’t want to be careful to check everything. This is kind of a bad habit. Better practice might be:
assert bpy.context.active_object. type = 'CURVE', "Select a curve"
Assert statements are kind of bad practice, but in a script meant for a very particular context, it’s safe to assume that the script should fail if the artist tries to execute it in the wrong context. If you don’t want the script to fail, do something like this:
assert bpy.context.active_object. type = 'CURVE'
print ("Select a Curve object")
This is exactly the same, except it will not return an error to Blender when you run it.