# blender -P boolean.txt # boolean_modifiers.py # I use blender 2.73a, on debian 6. # this scrtpt works. import bpy # Create a simple cube. bpy.ops.mesh.primitive_cube_add() # info window interpets this as bpy.ops.mesh.primitive_cube_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)) # Resize the cube. bpy.ops.transform.resize(value=(5, 3, 0.5)) # info window interpets this as bpy.ops.transform.resize(value=(5, 3, 0.5), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1) # Get the cube object and rename it. cube = bpy.context.object cube.name = 'cube' # Create a simple cylinder. bpy.ops.mesh.primitive_cylinder_add(radius = 1) # info window interpets this as bpy.ops.mesh.primitive_cylinder_add(radius=1, depth=2, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)) # Get the cylinder object and rename it. cyl = bpy.context.object cyl.name = 'cylinder' # Change the location of the cylinder. cyl.location = (5, 3, 0) # Create a boolean modifier named 'my_bool_mod' for the cube. mod_bool = cube.modifiers.new('my_bool_mod', 'BOOLEAN') # Set the mode of the modifier to DIFFERENCE. mod_bool.operation = 'DIFFERENCE' # Set the object to be used by the modifier. mod_bool.object = cyl # The modifier_apply function only works on the active object. # Set the cube as the active object. bpy.context.scene.objects.active = cube # Apply the modifier. res = bpy.ops.object.modifier_apply(modifier = 'my_bool_mod') # info window interpets this as bpy.ops.object.modifier_apply(modifier="my_bool_mod") # Delete the cylinder. cyl.select = True bpy.ops.object.delete() # info window interpets this as bpy.ops.object.delete() bpy.data.scenes['Scene'].render.filepath = 'boolean.png' bpy.ops.render.render( write_still=True )