# What are all values in bound_box?

I want to compute the total scene bounding box, so I can fit the scene in rendered image automatically. I have found bound_box. But why are there so many values

<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>
<bpy_float[3], Object.bound_box>


There should be 6 values (x_min,y_min,z_min) and (x_max,y_max,z_max)

• – p2or Jun 11 '15 at 16:00
• maybe you run the code twice and didn't realize, what code are you using and what object? (screenshots welcome) – zeffii Jun 11 '15 at 16:43
• @zeffi I probably did that – user877329 Jun 11 '15 at 16:57

You will get 8 values only,

>>> obj = bpy.context.active_object
>>> obj.bound_box
bpy.data.objects['Cube'].bound_box

>>> [v[:] for v in obj.bound_box]
[(-1.0, -1.0, -1.0),
(-1.0, -1.0, 1.0),
(-1.0, 1.0, 1.0),
(-1.0, 1.0, -1.0),
(1.0, -1.0, -1.0),
(1.0, -1.0, 1.0),
(1.0, 1.0, 1.0),
(1.0, 1.0, -1.0)]


for Suzanne it would be:

Here's some code I wrote about 2 years ago to get x.min, x.max, etc., and distance over the axis for x, y and z. With instructions how to use it. (I have this tucked away in a module so I just import the function when I need it)

import bpy
from mathutils import Vector

def bounds(obj, local=False):

local_coords = obj.bound_box[:]
om = obj.matrix_world

if not local:
worldify = lambda p: om * Vector(p[:])
coords = [worldify(p).to_tuple() for p in local_coords]
else:
coords = [p[:] for p in local_coords]

rotated = zip(*coords[::-1])

push_axis = []
for (axis, _list) in zip('xyz', rotated):
info = lambda: None
info.max = max(_list)
info.min = min(_list)
info.distance = info.max - info.min
push_axis.append(info)

import collections

originals = dict(zip(['x', 'y', 'z'], push_axis))

o_details = collections.namedtuple('object_details', 'x y z')
return o_details(**originals)

"""
obj = bpy.context.object
object_details = bounds(obj)

a = object_details.z.max
b = object_details.z.min
c = object_details.z.distance

print(a, b, c)

"""

• Ah, so it contains the coordinates of the box vertices. Then I need to loop to find the two min and max points – user877329 Jun 11 '15 at 16:52

Each object that has a bound_box property will return 8 values that represent the bounding information. The 8 values describe the corners of the bounding box itself.

If you have 16 values I presume that is because you have 2 objects in the scene (though it isn't clear from your question what you might have typed in to return all 16 values).