PYTHON: sequentially rendering multiple frame batches

NOTE: I wrote this tutorial without debugging it because my blender computer is rendering (using this method).

BY TOMORROW i will have debugged it, but be patient, or ask, if it doesn’t work the first time.
:smiley: (yay, sago smilies!)

Python- rendering multiple frame batches.

Using the method I will describe, you can render several separate batches of frames over several scenes. This means you can ready several animations to render before going on vacation- or even overnight- and run the script to render them all.
example:
you have three cameras rendering an animated model from different views. According to your calculations they will take about 2 hours to render each. It’s 11:00 pm, and you don’t want to get up at 1:00 and 3:00 am to change camera and start rendering the next batch. Here’s how you can set it up to do each in turn with a script.

ok, here’s how it works. Split the window and open it to the blender text editor.
Right-click -> add new.

first a little important syntax stuff, a # sign comments out a line.
for instance:


this line will be ignored by the python interpreter

this one won’t

this line will also be ignored.


the rest of this tutorial will be written as a script, you could

copy-paste it into blender and it’d work, but you wouldn’t learn

anything.

first, we need to get the data from blender, we use the import

function

import Blender

now that we have the data, we’ll make a function (mini program that can be called)

that will animate a frame batch

def anim(frames, camname, scn = None):
‘’'This function renders frame batches.

This triple-quoted section is a doc-string, the code ignores it.
Note: to call the function you'd use:
anim([1,61], 'camera1', 'myscene')

The frames variable is a list containing start and end frame.
The camera name variable is the name of the camera to render from.
The scn variable is the scene name, note is says ' = None ', this is
a default, meaning that if you just use:
anim([1,61], 'camera1')
it would not have an error, but rather assign Nothing to scn.

''' # <- this ends the docstring

# now, we get our scene

if scn: # if we have a name, (instead of None), do this:
    renderScene = Blender.Scene.Get(scn) # assign the scene by that name to 'renderScene'

else: # otherwise, do this:
    renderScene = Blender.Scene.GetCurrent() # assume current scene

# now we need our rendering context, i.e. the frames etc...
context = renderScene.getRenderingContext()

# now we assign our camera and frames
cam = Blender.Object.Get(camname) # get the camera
renderScene.setCurrentCamera(cam) # assign it as the current camera

context.sFrame = frames[0] # set the first variable in the list 'frames' to the startframe
context.eFrame = frames[1] # do the same for the endframe and second variable

# now we are ready to render...

context.renderAnim()

that should do it, you can also add stuff like paths to render to, check here:

http://www.blender3d.org/documentation/242PythonDoc/Render-module.html

for more stuff you can add

now to call it, here’s how:

heres three frame batches, you WILL NEED TO EDIT THIS TO YOUR NEEDS!!!

anim([1,50],‘topcam’,‘scene3’) # render 1-50 of scene3 from camera ‘topcam’

anim([34,65],‘sidecam’) # render 34-65 from the same scene with camera ‘sidecam’

anim([6,547],‘camera.003’,‘lost_attic_scene’) # render 6-547, you get the idea.

I’m using 2.46 and trying to get this script to work but no matter what I get this error in the console:

“IndentationError: expected an indented block”

anyone know why?!

hmmm… try indenting stuff :stuck_out_tongue:
howabout a code copy+paste if you still can’t get it :smiley:

This script is exactly what I need… if I could get it to work. The script I copied is following:

import Blender

def anim(frames, camname, scn = None):

if scn: 
renderScene = Blender.Scene.Get(scn) 

else: 
renderScene = Blender.Scene.GetCurrent() 

context = renderScene.getRenderingContext()

cam = Blender.Object.Get(camname)
renderScene.setCurrentCamera(cam)

context.sFrame = frames[0]
context.eFrame = frames[1]

context.renderAnim()


# If I understood correctly, this is where I write my stuff:

anim([1,146],'CAM_01','01') 
anim([147,220],'CAM_02','02')

#etc

when I run it, the line “if scn” gives me “IdentationError:expected an indented block”

Any help is very welcome :slight_smile:

Thanks

hi, this script should be like that:


import Blender

def anim(frames, camname, scn = None):
    if scn:
        renderScene = Blender.Scene.Get(scn)
    else:
        renderScene = Blender.Scene.GetCurrent()
    context = renderScene.getRenderingContext()
    cam = Blender.Object.Get(camname)
    renderScene.setCurrentCamera(cam)

    context.sFrame = frames[0]
    context.eFrame = frames[1]

    context.renderAnim()


# If I understood correctly, this is where I write my stuff:

anim([1,146],'CAM_01','01')
anim([147,220],'CAM_02','02')

#etc

In python, after a function or class declaration, the following code block (which belong to the function or class) must be ident with tab key (or spaces, but it is all the document with tab OR entirely with spaces, your call).

Edit: Damn ! That was old, sorry…