Blender python development workflow
- Edit the python script
- Keep a terminal open running the watch script e.g.
$ sh watch.sh
- See the rendered result
Each time you save the python script, the watch script gets notified and re-executes. I’m using feh (note the highlighted line in the watch script) to see the rendered result, since it refreshes automatically.
#/tmp/blender_mini_example.py
import bpy
# Delete the default cube
objs = bpy.data.objects
objs.remove(objs["Cube"], do_unlink=True)
# Add a sphere
bpy.ops.mesh.primitive_uv_sphere_add(location=(-2, 0, 0))
# /tmp/watch.sh
frame=1
filename=/tmp/foo_
mypython=blender_mini_example.py
myblender ()
{
blender \
--background \
--python $mypython \
--verbose 0 \
--factory-startup \
--use-extension 1 \
--render-output //$filename \
--render-frame $frame
}
# Run blender the first time
myblender
# Open the result
feh ${filename}"000$frame.png" &
# Re-run blender each time the script is saved
while inotifywait --event modify $mypython; do
myblender
done