Thanks to this answer, I'm using bpy.ops.view3d.camera_to_view_selected() to automatically place a camera so that it frames the selected object for rendering. But presumably there are lots of (x,y,z) locations within the scene where the camera could be placed and still frame the object.

Does anyone know how Blender decides which of these locations to move the camera to? For example, does it take the starting position of the camera into consideration?

  • 2
    $\begingroup$ From playing with this operator, it appears that: It does not change the angle of the camera. For a given angle (view vector) there is only 1 solution no matter what the starting position of the camera is. The camera aligns with the object so that it is "in front" of it in the camera's local space. It will require either trial and error or the time to delve into the source code to give a mathematical / algorithmic answer. $\endgroup$
    – TLousky
    Commented Dec 13, 2016 at 16:31
  • $\begingroup$ Yes, looks like you're right. Rotation is unaffected by bpy.ops.view3d.camera_to_view_selected(), so there's only one possible location for the camera. Thanks! $\endgroup$ Commented Dec 13, 2016 at 18:19

1 Answer 1


The bpy.ops.view3d.camera_to_view_selected() (View > Align View > Align Active Camera to Selected) operator allows you to position the camera to view the selected objects, and uses a variety of factors to determine the final location of the camera including the position and size of the selected objects and the current view settings of the 3D viewport.

It uses the following logic to calculate the final position of the camera:

  • It calculates the bounding box of the selected objects in the 3D space, which gives the minimum and maximum coordinates of the objects in each dimension.

  • It calculates the center point of the bounding box by taking the average of the minimum and maximum coordinates in each dimension.

  • It calculates the distance between the center point and the farthest corner of the bounding box.

  • It uses this distance and the current view settings, such as the field of view of the camera, to determine the optimal position with the current orientation of the camera to view the selected objects.

  • It sets the camera's location to the calculated position, which is only 1 possible point in space since the rotation is not affected by the operator.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .