# Bounding Box of multiple objects?

**URL:** https://forum.highend3d.com/t/bounding-box-of-multiple-objects/4871
**Category:** Maya
**Tags:** mel
**Created:** [October 18, 2003, 8:38pm UTC](https://forum.highend3d.com/t/bounding-box-of-multiple-objects/4871 "2003-10-18T20:38:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bentneuron](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/b/ea666f/32.png) [@bentneuron](https://forum.highend3d.com/u/bentneuron)
#### Post date: [October 18, 2003, 8:38pm UTC](https://forum.highend3d.com/t/bounding-box-of-multiple-objects/4871/1 "2003-10-18T20:38:45Z")

</div>

Does anybody know how to get the bounding box for a selection of multiple objects?

Thanks,  
-bN

---

<div class="post-metadata">

### Author: ![macaronikazoo](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@macaronikazoo](https://forum.highend3d.com/u/macaronikazoo)
#### Post date: [October 18, 2003, 10:24pm UTC](https://forum.highend3d.com/t/bounding-box-of-multiple-objects/4871/2 "2003-10-18T22:24:39Z")

</div>

this is from a larger script that gets a single animated bounding box for multiple mesh objects. happy to share it if you need it.

//takes a list of mesh objects, and returns an array containing: minBBX, minBBY, minBBZ, maxBBX, maxBBY, maxBBZ of the whole collection of mesh objects  
global proc float[] getAnimatedBoundsForMeshes( string $skinList[] ) {  
 float $bounds[];  
 float $skinMinBoundsX[];  
 float $skinMinBoundsY[];  
 float $skinMinBoundsZ[];  
 float $skinMaxBoundsX[];  
 float $skinMaxBoundsY[];  
 float $skinMaxBoundsZ[];

```
for( $skin in $skinList ) {
	$skinMinBoundsX[( `size $skinMinBoundsX` )] = `getAttr ( $skin + ".boundingBoxMinX" )`;
	$skinMinBoundsY[( `size $skinMinBoundsY` )] = `getAttr ( $skin + ".boundingBoxMinY" )`;
	$skinMinBoundsZ[( `size $skinMinBoundsZ` )] = `getAttr ( $skin + ".boundingBoxMinZ" )`;
	$skinMaxBoundsX[( `size $skinMaxBoundsX` )] = `getAttr ( $skin + ".boundingBoxMaxX" )`;
	$skinMaxBoundsY[( `size $skinMaxBoundsY` )] = `getAttr ( $skin + ".boundingBoxMaxY" )`;
	$skinMaxBoundsZ[( `size $skinMaxBoundsZ` )] = `getAttr ( $skin + ".boundingBoxMaxZ" )`;
	}

$skinMinBoundsX = `sort $skinMinBoundsX`;
$skinMinBoundsY = `sort $skinMinBoundsY`;
$skinMinBoundsZ = `sort $skinMinBoundsZ`;
$skinMaxBoundsX = `sort $skinMaxBoundsX`;
$skinMaxBoundsY = `sort $skinMaxBoundsY`;
$skinMaxBoundsZ = `sort $skinMaxBoundsZ`;

$bounds[0] = $skinMinBoundsX[0];
$bounds[1] = $skinMinBoundsY[0];
$bounds[2] = $skinMinBoundsZ[0];
$bounds[3] = $skinMaxBoundsX[( `size $skinMaxBoundsX` - 1 )];
$bounds[4] = $skinMaxBoundsY[( `size $skinMaxBoundsY` - 1 )];
$bounds[5] = $skinMaxBoundsZ[( `size $skinMaxBoundsZ` - 1 )];
return $bounds;
}
```

---

<div class="post-metadata">

### Author: ![bentneuron](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/b/ea666f/32.png) [@bentneuron](https://forum.highend3d.com/u/bentneuron)
#### Post date: [October 18, 2003, 11:06pm UTC](https://forum.highend3d.com/t/bounding-box-of-multiple-objects/4871/3 "2003-10-18T23:06:21Z")

</div>

Thanks! I was going to write it if there wasn't a simple flag I was missing, but now I don't have to. Whee!

---

<div class="post-metadata">

### Author: ![macaronikazoo](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@macaronikazoo](https://forum.highend3d.com/u/macaronikazoo)
#### Post date: [October 19, 2003, 12:40am UTC](https://forum.highend3d.com/t/bounding-box-of-multiple-objects/4871/4 "2003-10-19T00:40:41Z")

</div>

well, if there was a simple flag, i missed it too. ![](http://www2.highendnet.com/forums/icons/smile.gif)

---

<div class="post-metadata">

### Author: ![fishypants](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/b2d939/32.png) [@fishypants](https://forum.highend3d.com/u/fishypants)
#### Post date: [December 6, 2013, 1:08pm UTC](https://forum.highend3d.com/t/bounding-box-of-multiple-objects/4871/5 "2013-12-06T13:08:56Z")

</div>

If you want a shorter version of this I wrote this procedure:

global proc float[] GetMultipleBB(string $sel[]){  
float $bb[];  
  
// go through selection   
for($i=0; $i\<size($sel); $i++){  
float $thisBB[] = `xform -q -ws -bb $sel[$i]`;  
  
 // First check if bb[] is null, if so, just set the values  
if(size($bb) == 0){  
$bb = $thisBB;  
}  
else{  
if($thisBB[0] \< $bb[0]) $bb[0] = $thisBB[0];  
if($thisBB[1] \< $bb[1]) $bb[1] = $thisBB[1];  
if($thisBB[2] \< $bb[2]) $bb[2] = $thisBB[2];  
if($thisBB[3] \> $bb[3]) $bb[3] = $thisBB[3];  
if($thisBB[4] \> $bb[4]) $bb[4] = $thisBB[4];  
if($thisBB[5] \> $bb[5]) $bb[5] = $thisBB[5];  
}  
}

return $bb;  
[b]}

[/b]Just pass in an object selction like this:

string $sel[] = `ls -sl -fl`;  
float $selBB[] = GetMultipleBB($sel);

Also if you would like to find the center of all the selected objects I wrote this procedure as well:

global proc vector GetBBCenter(float $bb[]){  
vector $center;  
float $x = ($bb[0] + $bb[3]) / 2;  
float $y = ($bb[1] + $bb[4]) / 2;  
float $z = ($bb[2] + $bb[5]) / 2;  
$center = \<\>;  
return $center;  
[b]}&nbsp;

[/b]Just pass in the float array you recieved from GetMultipleBB() like so:  
string $sel[] = `ls -sl -fl`;  
float $selBB[] = GetMultipleBB($sel);  
vector $center = GetBBCenter($selBB);&nbsp;

---

<div class="post-metadata">

### Author: ![shobhit-khinvasara](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/s/e274bd/32.png) [@shobhit-khinvasara](https://forum.highend3d.com/u/shobhit-khinvasara)
#### Post date: [May 9, 2019, 9:52pm UTC](https://forum.highend3d.com/t/bounding-box-of-multiple-objects/4871/6 "2019-05-09T21:52:58Z")

</div>

An even shorter version is to use this command in mel:  
**exactWorldBoundingBox**

This takes a list of multiple objects as argument and returns the collective boundingBox of specified objects.
