A few observations about the code, nothing too serious… but you might get some insight. (if this seems too simplistic, then this post is directed at the potential total newcomer reading it). OK, Let’s suppose you have a bunch of these in your code.
bpy.ops.curve.primitive_nurbs_path_add( view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
Whenever you see a lot of repetition (like False, False, False…), it means you can probably write it differently. Consider something like this at the top of your code:
def selectLayer(layernum):
bools = []
for i in range(20):
if layernum == i:
bools.append(True)
else:
bools.append(False)
return tuple(bools)
you can test selectLayer by doing
print(selectLayer(0)) …or print(selectLayer(7))
so…layer 19 is the last one, because we start counting at 0, like lifts.
that allows you to write
bpy.ops.curve.primitive_nurbs_path_add( view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=selectLayer(0))
one step further
view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0)
are all default values, leaving them out produces the same effect. Their purpose is to let you modify the behavior of the function if you need to. Read this short explanation: default-argument-values and read PythonDoc/bpy.ops.curve.html, you’ll see they are optional.
in essence you can do
bpy.ops.curve.primitive_nurbs_path_add(layers=selectLayer(0))
and layers=selectLayer(0) is only required if you have some preference of what layer to use. Defining a function like selectLayer at the top of your code allows you to call it many times during your script and it will work for any valid layer. It helps to stick a line inside selectLayer that checks the input, and prints an error message if you accidentally pass a layer that is higher than 19 (or lower than 0…or a character/string). Error checking is good practice as you get more complex.
If the only layer you want to work on is 0, there is an even faster way…
layers=((True,)+(False,)*19)