How do you copy Cycles camera depth of field keyframes from one camera to another?

I’m writing a script where I need to copy camera settings from one camera to another. I’m able to copy things like this:

        left_cam.angle = center_cam.data.angle
        left_cam.clip_start = center_cam.data.clip_start
        left_cam.clip_end = center_cam.data.clip_end
        left_cam.dof_distance = center_cam.data.dof_distance
        left_cam.dof_object = center_cam.data.dof_object
        left_cam.shift_y = center_cam.data.shift_y
        left_cam.shift_x = (camera.stereo_camera_shift_x/2)+center_cam.data.shift_x
        left_cam_obj.location = -(camera.stereo_camera_separation/1000)/2,0,0
        left_cam_obj.rotation_euler = (0.0,0.0,0.0) # reset
        left_cam_obj.data.cycles.aperture_blades = bpy.data.objects["Camera"].data.cycles.aperture_blades
        left_cam_obj.data.cycles.aperture_size = bpy.data.objects["Camera"].data.cycles.aperture_size
        left_cam_obj.data.cycles.aperture_rotation = bpy.data.objects["Camera"].data.cycles.aperture_rotation
        left_cam_obj.data.cycles.aperture_type = bpy.data.objects["Camera"].data.cycles.aperture_type 
        left_cam_obj.data.cycles.aperture_ratio = bpy.data.objects["Camera"].data.cycles.aperture_ratio 

However, if I create keyframes for aperature_size, this code does not copy keyframes from one camera to another. It only copies the current value at the current frame.

How can I make a copy of the keyframes from one camera to another?

You don’t need to copy camera settings. Camera settings can be shared by multiple cameras already.

In the properties area click the camera symbol with the up and down arrows and the camera name to the right to use existing camera settings.

You can simply assign it to the camera via:


target.data = source.data

If you want to reuse the action - choose it in the dopesheet editor while the camera is selected or change


obj.animation_data.action =  bpy.data.objects['CameraAction']

If you don’t want to copy all keyframes you need to find and copy the correct fcurves in action.fcurves

Thanks for the info – I didn’t know it was possible to do that. Unfortunately, that won’t work for what I’m looking to do. I want to only copy certain kinds of keyframes, not link everything from one camera to another. (I cannot link the camera position/rotation at all, since I’m working on a stereoscopic camera add-in, where the position/rotation is going to be different per camera. However, the dof will be the same.)

Any other suggestions?