Scripting Blender
Contents
Why bother?
It's actually really easy, and the kind of geometrically regular 'box modelling' building a spaceship entails is well suited to scripting.
Next time you find yourself repeatedly doing the same sequence of operations to lots of different meshes or objects, consider writing a script. It may take a bit longer the first time, but once you know how you'll be much more efficient.
Walk through
We're going to write a script (more of a macro really) which takes the selected object, duplicates it, moves one duplicate 10 units forward on one axis, then shrinks it 10% on the other two axes.
Set up Blender
- Switch to 'Scripting' mode at the top, and in the Text pane's file widget hit 'New'. This is where our script will go. Type
import bpy
as the first line - that's the Blender PYthon module.
Perform the operations
Now we manually perform the operations we want the script to automate, to get an idea of the underlying python functions the interface uses. The arguments and output will appear in the top console pane. So, when I duplicate the starter box, move it ten units forwards on Y, then shrink it to .9 on X and Z, I get:
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "texture_space":False, "release_confirm":False})
bpy.ops.transform.resize(value=(0.9, 1, 1), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)
bpy.ops.transform.resize(value=(1, 1, 0.9), constraint_axis=(False, False, True), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)
Test
Copy those three statements from the top pane by right-clicking on each, then hitting ctrl-c. Paste them with ctrl-v just after the 'import bpy' statement. Congratulations, you've just written a Blender Python Script.
Hit 'Run script' below and you'll note that it all works, apart from failing to move the object along Y. By looking at the 0.9 arguments to the resizes, we can work out that the second dimension represents Y (figures... X, Y and Z), so we try putting 10 in as the second argument to the duplicate_move function. Test it again, and it works!
import bpy bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 10, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "texture_space":False, "release_confirm":False}) bpy.ops.transform.resize(value=(0.9, 1, 1), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False) bpy.ops.transform.resize(value=(1, 1, 0.9), constraint_axis=(False, False, True), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)
Through a similar process - working out what the interface is doing when you click the buttons, then sticking it together into primitive scripts - you'll soon be Blending much faster.