Copy camera aperture settings from main camera to stereo

Blender 2.63a
Stereoscopic Add-on 1.6.7 

Stereoscopic camera add-on from http://www.noeol.de/s3d/ helps generate stereo camera for 3D rendering.

It does the job well, except when working with DoF in Cycles. The add-on doesn’t copy the aperture setting from main camera the the stereo ones.

So I wrote a  script to automate this.

After setting up stereo cameras, create an empty text and paste this script.

import bpy

thisCam = bpy.data.objects["L_Camera"]

thisCam.data.cycles.aperture_blades = bpy.data.objects["Camera"].data.cycles.aperture_blades
thisCam.data.cycles.aperture_size = bpy.data.objects["Camera"].data.cycles.aperture_size
thisCam.data.cycles.aperture_rotation = bpy.data.objects["Camera"].data.cycles.aperture_rotation
thisCam.data.cycles.aperture_type = bpy.data.objects["Camera"].data.cycles.aperture_type

thisCam = bpy.data.objects["R_Camera"]

thisCam.data.cycles.aperture_blades = bpy.data.objects["Camera"].data.cycles.aperture_blades
thisCam.data.cycles.aperture_size = bpy.data.objects["Camera"].data.cycles.aperture_size
thisCam.data.cycles.aperture_rotation = bpy.data.objects["Camera"].data.cycles.aperture_rotation
thisCam.data.cycles.aperture_type = bpy.data.objects["Camera"].data.cycles.aperture_type

and run script.

Use Python script to generate render filepath

Blender 2.63a

When dealing with hundreds of shots, it could be painful to change the render filepath manually. So I wrote a script to automate this task based on .blend file name.

For example, I organise my files to be named like – S05C04_20120727.blend
Where S = scene, C = cut, and those 8 digits are the date this file has been changed.

I like my render filename to be the same with blend file but strip the date part out.

So, in Text Editor, paste this script

import bpy

currentfilename = bpy.path.display_name_from_filepath(bpy.data.filepath)

#this will store the current file name (with ".blend" truncated)
#into a variable called "currentfilename"
#so now, currentfilename hold a string 'S05C04_20120727'

renderfilepath = '//../render/'+currentfilename[:-9]+'/'+currentfilename[:-8]

#the [:-9] means truncate last 9 charactors out of the string
#so currentfilename[:9] would be 'S05C04'
#and currentfilename[:-8] would be 'S05C04_'
#renderpath variable would be '//../render/S05C04/S05C04_'

bpy.data.scenes['Scene'].render.filepath = renderfilepath
#don't forget to change 'Scene' to your actual scene name

Now press ‘Run Script’, you’ll see the render filepath change.

You can run this script with other blend file as well. For running from command line without opening the GUI, You have to add another line at the end

bpy.ops.wm.save_mainfile(filepath=bpy.data.filepath)
#to save changes that you've made.

and save it as a .py, like – renderpath.py

Now, from command line, run

blender -b S03C12_20120727.blend -P renderpath.py

This will change the setting inside the S03C12_20120727.blend file without the need to run Blender GUI.

Render from command line

Blender 2.63a

You can render a scene without opening the blender interface from command line

in windows – cmd
in linux or mac – terminal

Provided everything is set and ready to be rendered, to render animation type in command

blender -b filename.blend -a

For more advance options, you can use python script to change some settings in the blend file before render.

Create an empty text file with your favorite text editor (or in blender). Copy & paste these example settings.

import bpy

#change scene name to yours
Scenename = 'Scene'

# quality
bpy.data.scenes[Scenename].render.resolution_x = 2048
bpy.data.scenes[Scenename].render.resolution_y = 1080
bpy.data.scenes[Scenename].render.resolution_percentage = 50
bpy.data.scenes[Scenename].render.use_antialiasing = True
#bpy.data.scenes[Scenename].render.use_full_sample = True

# frame range
#bpy.data.scenes[Scenename].frame_start = 1
#bpy.data.scenes[Scenename].frame_end = 5

# image format
bpy.data.scenes[Scenename].render.image_settings.file_format = 'TIFF'
bpy.data.scenes[Scenename].render.image_settings.quality = 80
bpy.data.scenes[Scenename].render.image_settings.color_mode = 'RGBA'

# Cycles sampling
#bpy.data.scenes[Scenename].cycles.samples = 200

# stamp
bpy.data.scenes[Scenename].render.use_stamp = 1
bpy.data.scenes[Scenename].render.stamp_background = (0,0,0,1)

# output
#bpy.data.scenes[Scenename].render.filepath = '//render/test_'
bpy.data.scenes[Scenename].render.use_placeholder = True
bpy.data.scenes[Scenename].render.use_overwrite = False

# start render animation
bpy.ops.render.render(animation=True,scene=Scenename)

The important lines are the first and the last. Other lines can be changed to fit your need. The properties names are quite self-explained. The # sign is for comment line, will be ignored by the interpreter. You can hover the mouse over any boxes or buttons in Blender to see the script associated.

More details can be found at blender python api reference :

http://www.blender.org/documentation/blender_python_api_2_63_2/contents.html

 

Save the text as ‘setting.py’. You might put it in the same folder as the blend file for convenient.

To start render from command line, type

blender -b filename.blend -P setting.py