PDA

View Full Version : How do I get the size of a boundingbox?


Pixero
07-25-2004, 06:09 PM
Hi!
I need some help with how to write a melscript that sets a value to an attribute of a shading node based on the Y size value from a selected objects boundingbox.

Nicool
07-25-2004, 06:21 PM
Here it is buddy :)


float $surfaceMinX = `getAttr ($surface+".boundingBoxMinX")`;
float $surfaceMaxX = `getAttr ($surface+".boundingBoxMaxX")`;
float $surfaceMinY = `getAttr ($surface+".boundingBoxMinY")`;
float $surfaceMaxY = `getAttr ($surface+".boundingBoxMaxY")`;
float $surfaceMinZ = `getAttr ($surface+".boundingBoxMinZ")`;
float $surfaceMaxZ = `getAttr ($surface+".boundingBoxMaxZ")`;

Pixero
07-25-2004, 07:15 PM
Thanks Nicool but since Im a noob with mel I need more help.
This is my non working script so far:

global proc bbox(int $parentFlag)
{
int $i;
string $temp, $selString[];
string $surface[] = `ls -long -sl`;
float $surfaceMaxY;
if (!(size ($surface))) error ("Nothing selected...\n");
for ( $i = 0; $i < size ($surface); $i++ )
{
$temp = $surface[$i];
float $surfaceMaxY = `getAttr ($temp + ".boundingBoxMaxY")`;
}
setAttr setRange1.oldMaxY = $surfaceMaxY;
}

sbp
07-25-2004, 08:36 PM
Hi,

This might be a little easier and more convenient to use.

// get selection
string $sel[] = `ls -sl -o`;
// create a plusMinusAverage node
string $pmaNode = `createNode "plusMinusAverage"`;
// connect the boundingbox y to the 1d input list of plusMinusAverage
connectAttr -f ($sel[0] + ".bbxy") ($pmaNode + ".i1[0]");
connectAttr -f ($sel[0] + ".bbny") ($pmaNode + ".i1[1]");
// set the op to subtract
setAttr ($pmaNode + ".op") 2;
// connect the output to whatever attribute you want driven
connectAttr -f ($pmaNode + ".o1") someNode.someAttr;

Pixero
07-25-2004, 09:05 PM
Great thanks!

CGTalk Moderation
01-18-2006, 07:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.