PDA

View Full Version : HELP!: Copy Attributes Script


andrewmartin
06-30-2006, 12:55 AM
Hi,

My knowledge of MEL is very limited (a euphemism for non-existent), so I was hoping someone here could help me out.

The very basic function of the script I want to make is to copy the values of one objects attributes, and paste them into the corresponding attributes of another object. So if I select two objects and execute the script, the second objects translateX, for example, changes to the value of the first objects translateX.

If that didn't make any sense, let me know and I'll try and explain it better.

Thanks!

dbsmith
06-30-2006, 01:19 AM
//Copy trans/rotate/scale attributes from first selected object to all others
{

string $objs[] = `ls -sl`;

string $from = $objs[0];

float $trans[] = `getAttr ( $from + ".translate")`;

float $rot[] = `getAttr ( $from + ".rotate")`;

float $scale[] = `getAttr ( $from + ".scale")`;

for($i=1;$i < size($objs); $i++){



setAttr ($objs[$i] + ".translateX") $trans[0];

setAttr ($objs[$i] + ".translateY") $trans[1];

setAttr ($objs[$i] + ".translateZ") $trans[2];

setAttr ($objs[$i] + ".rotateX") $rot[0];

setAttr ($objs[$i] + ".rotateY") $rot[1];

setAttr ($objs[$i] + ".rotateZ") $rot[2];

setAttr ($objs[$i] + ".scaleX") $scale[0];

setAttr ($objs[$i] + ".scaleY") $scale[1];

setAttr ($objs[$i] + ".scaleZ") $scale[2];

}

}



This will take the attributes of the first object you select and transfer them to all other selected objects. But this means that the objects will all stack up in the same place. It should be easy enough for you to modify the code yourself now if you arent getting the desired results (eg if you just want translate, not rotate or scale, just comment out a few lines. Good luck

andrewmartin
06-30-2006, 02:10 AM
Thanks! It works perfectly!

I now have to try and build on that to apply it to my original problem. It shouldn't be too difficult for me, but I may require further help in the not-too-distant future, so please stay subscribed to this thread! :)

Thanks again!

Mikademius
06-30-2006, 12:32 PM
Subscribed for further assistance ;) Bring it on

CGTalk Moderation
06-30-2006, 12:32 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.