Finding the length of the contents of a group

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2011   #1
Question Finding the length of the contents of a group

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
 
Old 02 February 2011   #2
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");
__________________
------------------------------------------------------
blog ----- portfolio
 
Old 02 February 2011   #3
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:14 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.