CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
Thread Tools Search this Thread Display Modes
Old 02-14-2011, 12:42 PM   #1
New Member
Pete Chapman
Manchester, United Kingdom
Join Date: Aug 2010
Posts: 17
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,

Old 02-14-2011, 02:16 PM   #2
Vertex Pusher
pixelranger's Avatar
André Hitsoy
London, United Kingdom
Join Date: Apr 2002
Posts: 437
Send a message via MSN to pixelranger

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-14-2011, 02:16 PM   #3
CGTalk Moderation
CGTalk Forum Leader
Join Date: Sep 2003
Posts: 1,066,478
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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
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
Society of Digital Artists

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

All times are GMT. The time now is 05:09 AM.

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