3
$\begingroup$

I am getting started with the Blender Python API and there is something I do not understand. Lets say I have an object called "myObject" and I wanted to get its dimensions, then I type

bpy.data.objects["myObject"].dimensions

in the python console and get the result. The API http://www.blender.org/documentation/blender_python_api_2_71_release/bpy.types.Object.html#bpy.types.Object states, that an object also has a bound_box. But if I type

bpy.data.objects["myObject"].bound_box

simply the command I typed is returned! Why is that and how could I have known from the doc of the API? Also, when I type

bpy.data.objects["myObject"].show_bounds

it only returns "false". Why? If I go to the object properties panel and click "Bound" the bounding box is drawn. Why does that work and doing the same (?) via the console does not?

Thank you!

$\endgroup$
  • $\begingroup$ Ah, I figured out that one simply has to set show_bounds to True to be able to see the bounding box of an object. However, I have still not figured out how to see the values of the bounding box $\endgroup$ – user1809923 Jul 15 '14 at 11:50
3
$\begingroup$

Object.bound_box does not contain mathutils-types like Matrix or Vector, it's a plain property array of float[3] which has no representation format like other types do.

You need to iterate over all elements and print them, e.g.:

for b in bpy.context.object.bound_box:
    print(b[:])

# (-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)

Or make a list of Vector objects:

[Vector(b) for b in bpy.context.object.bound_box]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.