I’ve been looking for a way to automate rendering of several scenes in Blender, either from the same file or from different files, and I can’t seem to get it working.
There are two ways to do this, as far as I can see. Option 1 is to save many different scenes to the same .blend file, and cycle through each scene, rendering it as I go. That code would look something like this:
for Scn in bpy.data.scenes:
# Set active scene
bpy.context.screen.scene = Scn
# Set rendering options
Scn.render.file_format = ‘PNG’
Scn.render.filepath = ‘/some/unique/file/path.png’ # (I of course vary this with each loop iteration)
… However, this doesn’t work - the render command at the end of the loop will repeatedly render whichever scene is active as the script is called. Basically, the “scene=” argument in the render() command seems not to work.
The second way I could do this is to store all my scenes in different .blend files, open each one and render it in sequence. However, it seems that once a .blend file is opened via
… then the script stops dead in its tracks and no further commands are executed. That is:
This never executes.
Scn = bpy.context.scene
Anyone have any idea how I might proceed? Is there some other option I haven’t considered? Also, even if it’s not the best way, I’m particularly interested in whether the python API can handle opening and closing multiple files within the same script…