How do I change the DoF settings of the active camera using python? I want to change the DoF distance of the active camera in a scene using a script. So far I have written:

bpy.data.cameras[0].dof_distance = distance #"distance" is the variable I want to use


But that sets the DoF distance for the camera that comes first in the outliner (alphabetically), which is not necessarily the active one.

So I tried getting the active camera property from the scene settings using

bpy.context.scene.camera.dof_distance = distance


But that does not work at all, because this method only returns the object, but not the "camera-properties" (as far as I get it).

How can I make this work?
bpy.context.scene.camera returns the active camera in the scene. In order to change your Depth of Field settings use the Console, Python Tooltips or the API to find each corresponding property.

&gt;&gt;&gt; active_cam = bpy.context.scene.camera
&gt;&gt;&gt; bpy.data.cameras[active_cam.name].
                                      angle
                                      angle_x
                                      angle_y
                                      dof_distance
                                      dof_object
                                      ...
&gt;&gt;&gt; bpy.data.cameras[active_cam.name].dof_distance = 7