Scripting in Blender with Python, and working on the API
Moderators: jesterKing, stiv
-
baze
- Posts: 0
- Joined: Thu Feb 03, 2011 9:02 pm
Post
by baze » Thu Feb 03, 2011 9:24 pm
Hi,
I could find a python script for Blender 2.56Beta that would render all or selected cameras in a batch mode. So I made it my self and just want to share it here.
Just run like this:
blender -b your_file.blend -P render_all_cameras.py
... or to render just cameras containing text "east":
blender -b your_file.blend -P render_all_cameras.py cameras=east
----- render_all_cameras.py -------------
Code: Select all
# Render all cameras or cameras containing text given with command line argument "cameras".
# Example:
# Let's say test.blend file contains cameras "east.01", "east.02", "west.01", "west.02"
# By executing command "blender -b your_file.blend -P render_all_cameras.py" all 4 cameras will be rendered.
# Command "blender -b your_file.blend -P render_all_cameras.py cameras=east" will render "east.01" and "east.02" cameras.
# Command "blender -b your_file.blend -P render_all_cameras.py cameras=01" will render "east.01" and "west.01.02" cameras.
import bpy, bgl, blf,sys
from bpy import data, ops, props, types, context
print("\nThis Python script will render your scene with all available cameras")
print("or with camera(s) matching command line argument 'cameras'")
print("")
print("Usage:")
print("Render all cameras:")
print("blender -b your_file.blend -P render_all_cameras.py\n")
print("Render only matching cameras:")
print("blender -b your_file.blend -P render_all_cameras.py cameras=east\n")
cameraNames=''
# Loop all command line arguments and try to find "cameras=east" or similar
for arg in sys.argv:
words=arg.split('=')
if ( words[0] == 'cameras'):
cameraNames = words[1]
print('rendering cameras containing [' + cameraNames + ']')
print('\nPrint Scenes...')
sceneKey = bpy.data.scenes.keys()[0]
print('Using Scene[' + sceneKey + ']')
# Loop all objects and try to find Cameras
print('Looping Cameras')
c=0
for obj in bpy.data.objects:
# Find cameras that match cameraNames
if ( obj.type =='CAMERA') and ( cameraNames == '' or obj.name.find(cameraNames) != -1) :
print("Rendering scene["+sceneKey+"] with Camera["+obj.name+"]")
# Set Scenes camera and output filename
bpy.data.scenes[sceneKey].camera = obj
bpy.data.scenes[sceneKey].render.file_format = 'JPEG'
bpy.data.scenes[sceneKey].render.filepath = '//camera_' + str(c)
# Render Scene and store the scene
bpy.ops.render.render( write_still=True )
c = c + 1
print('Done!')
--------------------------------------
-
danielbaggio
- Posts: 0
- Joined: Sun Aug 09, 2009 10:46 pm
- Location: São José dos Campos, Brazil
Post
by danielbaggio » Wed Mar 02, 2011 5:19 am
Thank you a lot, man!!!
-
djay86
- Posts: 0
- Joined: Mon Apr 08, 2013 7:30 am
Post
by djay86 » Mon Apr 08, 2013 7:40 am
baze I need it this script.. Thanks alot taking time to help!!
-
botgirl
- Posts: 0
- Joined: Wed Apr 24, 2013 10:04 am
Post
by botgirl » Wed Apr 24, 2013 10:09 am
hey there,
i'm a total nOOb with blender, but i'm forced right now to use this batch cam render script, since i have a lot of characters, which need to be rendert from different camera angles.
right now i'm hitting the render button, wait for some hours, get the next cam, hit the render again a.s.o.
so this script is perfect for me.
unfortunately i'm too new to know my way around python, tried severel things the internet suggestet, but couldnt get the script to run..
would u be so kind to post a how-to-use this script ?
that would be great ....
thank u!
-
stiv
- Posts: 0
- Joined: Tue Aug 05, 2003 7:58 am
- Location: 45N 86W
Post
by stiv » Wed Apr 24, 2013 3:46 pm
The BPy API has changed some in the last two years, so the script will likely need some rework to get it functional again.
right now i'm hitting the render button, wait for some hours, get the next cam, hit the render again a.s.o.
Just off the top of my head, one way to deal with this is to make copies of the scene with everything linked except for the camera. Then you can just render all the scenes from the command line.
-
anachronist
- Posts: 0
- Joined: Sat Sep 21, 2013 9:54 am
Post
by anachronist » Sat Sep 21, 2013 9:57 am
Hey,
I just wanted to share my (slightly different) version of the script. Now it runs with my version of Blender (v2.66.1) and renders the complete animation (I simply modified two lines)...
Code: Select all
# Render all cameras or cameras containing text given with command line argument "cameras".
# Example:
# Let's say test.blend file contains cameras "east.01", "east.02", "west.01", "west.02"
# By executing command "blender -b your_file.blend -P render_all_cameras.py" all 4 cameras will be rendered.
# Command "blender -b your_file.blend -P render_all_cameras.py cameras=east" will render "east.01" and "east.02" cameras.
# Command "blender -b your_file.blend -P render_all_cameras.py cameras=01" will render "east.01" and "west.01.02" cameras.
import bpy, bgl, blf,sys
from bpy import data, ops, props, types, context
print("\nThis Python script will render your scene with all available cameras")
print("or with camera(s) matching command line argument 'cameras'")
print("")
print("Usage:")
print("Render all cameras:")
print("blender -b your_file.blend -P render_all_cameras.py\n")
print("Render only matching cameras:")
print("blender -b your_file.blend -P render_all_cameras.py cameras=east\n")
cameraNames=''
# Loop all command line arguments and try to find "cameras=east" or similar
for arg in sys.argv:
words=arg.split('=')
if ( words[0] == 'cameras'):
cameraNames = words[1]
print('rendering cameras containing [' + cameraNames + ']')
print('\nPrint Scenes...')
sceneKey = bpy.data.scenes.keys()[0]
print('Using Scene[' + sceneKey + ']')
# Loop all objects and try to find Cameras
print('Looping Cameras')
c=0
for obj in bpy.data.objects:
# Find cameras that match cameraNames
if ( obj.type =='CAMERA') and ( cameraNames == '' or obj.name.find(cameraNames) != -1) :
print("Rendering scene["+sceneKey+"] with Camera["+obj.name+"]")
# Set Scenes camera and output filename
bpy.data.scenes[sceneKey].camera = obj
#bpy.data.scenes[sceneKey].render.file_format = 'JPEG'
bpy.data.scenes[sceneKey].render.filepath = '//camera_' + str(c) + '_'
# Render Scene and store the scene
bpy.ops.render.render( animation=True )
c = c + 1
print('Done!')