Correct usage of bound_box property?

Hello everyone,

Me again. I’m having some trouble figuring out how to use the bpy.data.objects[“Obj”].bound_box property. Printing the property only gives me

<bpy_float[8], Object.bound_box> #Obj is a cube = 8 verts

Printing bound_box[n] (where n is any number from 0 to 8) gives me

<bpy_float[3], Object.bound_box>

I’m not sure where the 3 comes from.

Also, using the following code throws me an error, saying the key is invalid and should be an int (which it is, isn’t it?).

 for i in obj.bound_box:
    print(obj.bound_box[i])

As for my last question on this subject, how could I use this information properly? Let’s say I want to create an object on a random location, as long as it’s (not) intersecting with this example’s obj. I could easily cheat for a cube object (randrange for x, y, z, determining min and max for each by adding/ subtracting dimension/2 to the center point), but I can’t for more complex shapes.

This is really boggling my mind right now. =P

As always, thanks in advance!

Hi there!

At your third published code i is obviously NOT an integer and therefore Blender python correctly gives you an error message. In your cycle i is a vector with 3 coordinates (see below).

I dont know if your question is for 2.5x, but in 2.49b the following works pretty well for listing verts of object’s bounding box:

sce = Scene.GetCurrent()
ob = Object.GetSelected()[0]
me = ob.getData(mesh=1)
bb = ob.getBoundBox()
for v in bb:
    print v
print
print bb[5]
print

You see - ALL elements v are 3D-vectors!

bb = ob.getBoundBox(1) will give you the object’s bounding box in global space.

At the end, the sixth element of the object’s bounding box is printed by a direct call to its value.

Hope this helps you!

Regards,

Do’w, of course i isn’t an integer. I was thinking in AS3/ C-syntax.

for(var i:int; i<5; i++){
    trace(i); //0,1,2,3,4
}

I’m using 2.5x, but thanks for the code! =)
This definitely cleared things up for me. Do you know if there is also a method for using these co-ordinates as one given set (i.e. to set the mesh up as a domain)?

I dont quite understand your last question. If you could re-state it, would be better for me :eek:

Ok, sorry. =) What I meant was: Can I use the co-ordinates given from Object.bound_box as a domain, and use it as such? I.e.: Generating a random co-ordinate within this domain/ these bound_box co-ordinates. I also just found Atom’s thread in which he’s trying to achieve a check to see if a point is inside a convex mesh, so I’m assuming I’m looking for an easy way that doesn’t exist.

Definitely, you can generate a 3D-figure by using bounding-box coordinates but it wont tell you if a point is inside a body whose bounding-box you’re using for reference as it may have a more complex shape. You cannot change values in the bounding-box itself, unless its body it refers to also changes size, shape, etc.

Is that what you’d like to do?

You may want to check out the meandering path script here:
http://blenderartists.org/forum/showthread.php?t=108183&highlight=meandering

PGR1972 creates a bounding box and then makes random points in side the box to connect lines to.

I use the bounding box features to determine the width of characters that I created in my BlendText script. Because the script manages the text for you, it had to know how wide each letter was. I also used the bounding box for my effector code to determine if the effector was close enough to a letter to warrant further evaluation.

Lots of uses for bounding box once you start considering algorithmic animation.

Here is 2.49 code:


def returnBoundingBoxWidth(passedObjectName):
    # Found here: http://blenderartists.org/forum/showthread.php?t=114293&highlight=getBoundBox
    passedObject = fetchIfObject(passedObjectName)
    if passedObject != None:
        bb = passedObject.getBoundBox(1)
        w = bb[5].x - bb[1].x
        return w
    else:
        # Make this message indent one level.
        addToPrefix ()
        toConsole ("returnBoundingBoxWidth: Processing invalid object [" + passedObjectName + "].")
        removeFromPrefix()
        return 0.0

Here is 2.5 code:


def returnBoundingBoxWidth(passedObjectName):
    passedObject = fetchIfObject(passedObjectName)
    if passedObject != None:
        w = passedObject.dimensions[0]
        return w
    else:
        # Make this message indent one level.
        addToPrefix ()
        toConsole ("returnBoundingBoxWidth: Processing invalid object [" + passedObjectName + "].")
        removeFromPrefix()
        return 0.0

def returnBoundingBoxHeight(passedObjectName):
    passedObject = fetchIfObject(passedObjectName)
    if passedObject != None:
        h = passedObject.dimensions[1]
        return h
    else:
        # Make this message indent one level.
        addToPrefix ()
        toConsole ("returnBoundingBoxHeight: Processing invalid object [" + passedObjectName + "].")
        removeFromPrefix()
        return 0.0

def returnBoundingBoxDepth(passedObjectName):
    passedObject = fetchIfObject(passedObjectName)
    if passedObject != None:
        d = passedObject.dimensions[21]
        return d
    else:
        # Make this message indent one level.
        addToPrefix ()
        toConsole ("returnBoundingBoxDepth: Processing invalid object [" + passedObjectName + "].")
        removeFromPrefix()
        return 0.0

@ Atom
interesting idea this bound box thing for Text
but can this use the new 25 Text 3D mode?

got same problem for letters/ words this week

i need to add scale numbers around a circle to make a polar graph
and function of the scale i use the values can be from 1 to several letters long

so could this box thing could be used to locate the words on the outside of the polar graph ?

i can show a pic if you want

Thanks

Argh, you’re right Adibos, I completely forgot the fact this is only the box surrounding the object; not the convex hull/ object itself. I don’t know what I was thinking. o.O
Thanks for the script though Atom, I’ll still have fun playing with it.=)

@Ricky: You could write another script to do that, but that is what BlendText is for. Just type in your numbers as a string, pick a circular path and add a scale IPO.

well i already got something almost working
see WIP IES thread for polar graph i did
but it’s in 2.5 not 2.49

is your script beginning to work in 2.5
might be usefull later on for other graph may be

i also implemented an atuo scaling feature for this polar graph

Thanks