PDA

View Full Version : Finding the length of the contents of a group


mrp86
02-14-2011, 11:42 AM
I'm trying to work out if there is a better way to get the dimentions of the contents of a group.

At the moment I can select the two objects at the extremities, and then assign locators and create a distance dimension node, what I want to be able to do is select the group and return a float value of the total length in the X and Y axis.

Kind regards,

Pete

pixelranger
02-14-2011, 01:16 PM
Try this. Should work on meshes, groups, anything, really, including multiple selections:

string $sel[] = `ls -sl`;
string $evalItems[] = {};
for ($each in $sel){
string $transforms[] = `listRelatives -c -ad -typ "transform" $each `;
if (`nodeType $each` == "transform"){
$transforms[size($transforms)] = $each;
}
for ($transform in $transforms){
string $shapes[] = `listRelatives -s $transform`;
if (`size($shapes)`!= 0){
$evalItems[size($evalItems)] = $transform;
}
}
} // print($evalItems)

float $bBminX[] = {};
float $bBmaxX[] = {};
float $bBmaxY[] = {};
float $bBminY[] = {};
float $bBmaxZ[] = {};
float $bBminZ[] = {};

for ($each in $evalItems){
float $bB[] = `polyEvaluate -b $each`;
$bBminX[size($bBminX)] = $bB[0];
$bBmaxX[size($bBmaxX)] = $bB[1];
$bBminY[size($bBminY)] = $bB[2];
$bBmaxY[size($bBmaxY)] = $bB[3];
$bBminZ[size($bBminZ)] = $bB[4];
$bBmaxZ[size($bBmaxZ)] = $bB[5];
}

float $bBminXSorted[] = `sort $bBminX`;
float $bBmaxXSorted[] = `sort $bBmaxX`;
float $bBminYSorted[] = `sort $bBminY`;
float $bBmaxYSorted[] = `sort $bBmaxY`;
float $bBminZSorted[] = `sort $bBminZ`;
float $bBmaxZSorted[] = `sort $bBmaxZ`;

float $totalMinX = $bBminXSorted[0];
float $totalMaxX = $bBmaxXSorted[size($bBmaxXSorted)-1];
float $totalMinY = $bBminYSorted[0];
float $totalMaxY = $bBmaxYSorted[size($bBmaxYSorted)-1];
float $totalMinZ = $bBminZSorted[0];
float $totalMaxZ = $bBmaxZSorted[size($bBmaxZSorted)-1];

float $width = abs($totalMaxX - $totalMinX);
float $height = abs($totalMaxY - $totalMinY);
float $length = abs($totalMaxZ - $totalMinZ);
float $diagonalMinMaxXY = sqrt(pow($width,2) + pow($height,2));
float $diagonalMinMaxXYZ = sqrt(pow($diagonalMinMaxXY,2) + pow($length,2));

print ("Width (X) is " + $width + ".\n");
print ("Height (Y) is " + $height + ".\n");
print ("Length (Z) is " + $length + ".\n");
print ("The 2d distance from minX,minY to maxX,maxY is " + $diagonalMinMaxXY + ".\n");
print ("The 3d distance from minX,minY,minZ to maxX,maxY,maxZ is " + $diagonalMinMaxXYZ + ".\n");

CGTalk Moderation
02-14-2011, 01:16 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.