Dev:Py/Scripts/Cookbook/Code snippets/Batch run
< Dev:Py | Scripts | Cookbook | Code snippets
Batch run
The program runs all scripts in the object and simulation folders. The main purpose is to verify that all scripts run correctly, or at least that they can be executed without causing errors.
Most scripts do not run in earlier versions of Blender. To ensure that we are not stuck with an outdated Blender, we first check the current Blender version, which is available as bpy.app.version
.
#----------------------------------------------------------
# File batch.py
#----------------------------------------------------------
import bpy, sys, os, mathutils
from mathutils import Vector
# Check Blender version
version = (2, 57, 0)
if bpy.app.version < version:
msg = 'Blender too old: %s < %s' % (bpy.app.version, version)
raise NameError(msg)
# Delete all old objects, so we start with a clean slate.
scn = bpy.context.scene
for ob in scn.objects:
scn.objects.active = ob
print("Delete", ob, bpy.context.object)
bpy.ops.object.mode_set(mode='OBJECT')
scn.objects.unlink(ob)
del ob
# Path to the code. You must change this unless you place the
# snippets folder in your home directory
scripts = os.path.expanduser('~/snippets/scripts/')
for folder in ['object', 'simulation', 'interface']:
sys.path.append(scripts+folder)
print(sys.path)
origin = Vector((0,0,0))
# Meshes and armatures
origin[2] = 0
import meshes
meshes.run(origin)
origin[0] += 5
import armature
armature.run(origin)
origin[0] += 5
import rigged_mesh
rigged_mesh.run(origin)
origin[0] += 5
import shapekey
shapekey.run(origin)
origin[0] += 5
# Three ways to construct objects
import objects
objects.run(origin)
origin[0] += 5
# Materials and textures
origin[2] = 5
origin[0] = 0
import material
material.run(origin)
origin[0] += 5
import texture
texture.run(origin)
origin[0] += 5
import multi_material
multi_material.run(origin)
origin[0] += 5
import uvs
uvs.run(origin)
origin[0] += 5
import chain
chain.run(origin)
# Actions and drivers
origin[2] = 25
origin[0] = 0
import ob_action
ob_action.run(origin)
origin[0] += 5
import pose_action
pose_action.run(origin)
origin[0] += 5
import epicycle
epicycle.run(origin)
origin[0] += 5
import driver
driver.run(origin)
# Simulations
origin[2] = 15
origin[0] = 0
import hair
hair.run(origin)
origin[0] += 5
import edit_hair
edit_hair.run(origin)
origin[0] += 5
import particle
particle.run(origin)
origin[0] += 5
import cloth
cloth.run(origin)
origin[0] += 5
import softbody
softbody.run(origin)
origin[2] = 10
origin[0] = 0
import fire
fire.run(origin)
origin[0] += 5
import flags
flags.run(origin)
origin[0] += 5
import smoke
smoke.run(origin)
origin[0] += 5
import crystal
crystal.run(origin)
origin[0] += 5
origin[2] = -4.02
origin[0] = -10
import pile
pile.run(origin)
# Restore render engine
bpy.context.scene.render.engine = 'BLENDER_RENDER'
# Other data types
origin[2] = 20
origin[0] = 0
import text
text.run(origin)
origin[0] += 5
import lattice
lattice.run(origin)
origin[0] += 5
import curve
curve.run(origin)
origin[0] += 5
import path
path.run(origin)
import camera
camera.run(Vector((0,0,0)))
# Layers and groups
import layers
layers.run()
import groups
groups.run()
# Restore layers after layers and groups
scn.layers[0] = True
for n in range(1,20):
scn.layers[n] = False
# View
import world
world.run()
import view
view.run()
At frame 71, your screen should look as the picture below. The rendered version appears on the front page.