PDA

View Full Version : How do you return the scale of an object?


facelaunch
04-26-2006, 06:15 AM
How do you return the scale of an object in the x, y, and z domains?
i.e You type MEL script for a particular object to return is scale.

Thanks

john_homer
04-26-2006, 06:47 AM
you can query any attribute with "getAttr" check it out in the online docs..

for example to get the scaleX of "mySphere"..

getAttr mySphere.scaleX;

or if you want to actually use it ;)..

float $sx = `getAttr mySphere.scaleX`;
print $sx;

or to put all 3 scales into 1 variable..
float $theScales[] = `getAttr mySphere.scale`;

etc...

j.

facelaunch
04-26-2006, 12:17 PM
Thanks for your reply. Thats perfect.

Navi
11-01-2006, 04:51 PM
What if you scaled an object to say 10 10 10, then froze transformation. When you get the .scale value it justs returns a value of 1 1 1. Is it possible to get the real value some how?

grantimus
11-01-2006, 05:23 PM
What if you scaled an object to say 10 10 10, then froze transformation. When you get the .scale value it justs returns a value of 1 1 1. Is it possible to get the real value some how?
I'm afraid not. When you freeze your transforms, Maya resets your tranform information.

Navi
11-01-2006, 11:53 PM
grantimus - thanks for the quick response.

Here's a work around I just wrote to match the scale of one object to another.


global proc vV_matchScale() {
// select object then target.
string $sl[] = `ls -sl`;

string $object = $sl[0];
string $target = $sl[1];

// get the bounding box info.
float $xfrmTrgt[] = `exactWorldBoundingBox $target`;
float $xfrmObj[] = `exactWorldBoundingBox $object`;

// calculate the size of the targets bounding box.
float $xSizeT = ( $xfrmTrgt[3] - $xfrmTrgt[0]);
float $ySizeT = ( $xfrmTrgt[4] - $xfrmTrgt[1]);
float $zSizeT = ( $xfrmTrgt[5] - $xfrmTrgt[2]);

// calculate the size of the objects bounding box.
float $xSizeO = ( $xfrmObj[3] - $xfrmObj[0]); // "world scale"
float $ySizeO = ( $xfrmObj[4] - $xfrmObj[1]); // "world scale"
float $zSizeO = ( $xfrmObj[5] - $xfrmObj[2]); // "world scale"

// freeze transform on object so we have a constant value to work with.
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $object;

// I now need the ratio of size difference.
$scaleValX = ($xSizeT/$xSizeO);
$scaleValY = ($ySizeT/$ySizeO);
$scaleValZ = ($zSizeT/$zSizeO);

// set the scale of the object so that it matches the targets.
setAttr ($object + ".scaleX") ($scaleValX);
setAttr ($object + ".scaleY") ($scaleValY);
setAttr ($object + ".scaleZ") ($scaleValZ);

}//end matchScale().


* script right now assumes that the "objects" (target is fine) scale value does not have freeze transform applied to it. I'll have to think up a way to do it with it applied to it later.

edit: ** I made the changes in order for it to be applied to objects with freeze transform applied to it.

ashishdantu
11-02-2006, 03:48 AM
hi,

i have a similar concept based script.. but it is written to produce a simple cube based on selected faces of a polygon..

some think like u want to make a low-res representation of ur set or something..


string $selTree[]=`ls -sl -flatten`;
string $selFaces="";
string $tmp[];
tokenize $selTree[0] "." $tmp;
string $newDup[]=`duplicate -rr $tmp[0]`;

for ($i=0;$i<size($selTree);$i++)
{
string $tmp1[];
tokenize $selTree[$i] "." $tmp1;
$selFaces+=($newDup[0]+"."+$tmp1[1]+" ");
}

eval ("select -r "+$selFaces);
InvertSelection;
delete;

select $newDup[0];
string $selTree[]=`ls -sl`;

float $piv[]=`xform -q -ws -piv $selTree[0]`;
CenterPivot $selTree[0];
float $bbox[] = `exactWorldBoundingBox $selTree[0]`;
string $cubeLoww[]=`polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -tx 1 -ch 1 -name ($selTree[0]+"_Low")`;
delete `parentConstraint $selTree[0] $cubeLoww[0]`;
move $piv[0] $piv[1] $piv[2] ($selTree[0]+".rotatePivot") ($selTree[0]+".scalePivot");
scale (($bbox[3]-$bbox[0])) (($bbox[4]-$bbox[1])) (($bbox[5]-$bbox[2]));
move $piv[0] $piv[1] $piv[2] ($cubeLoww[0]+".rotatePivot") ($cubeLoww[0]+".scalePivot");

delete $newDup[0];


the code can be optimized.... but i'll need some push to do so...
-cheers

CGTalk Moderation
11-02-2006, 03:48 AM
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.