替换物件 MEL

Maya有个功能,可以将所有选起来的物件,替换为最后选取的物件。但使用时,我常发现旋转度会有问题,所以自己用MEL写了一个替代方案,程式如下

1

[code language=”javascript”]
string $sel_group[]=`ls -sl`;
string $dupO[];
string $prnO[];

string $obj,$target,$newObj,$theParent;
float $ii0=1;

float $tx,$ty,$tz,$rx,$ry,$rz,$sx,$sy,$sz;

for ($obj in $sel_group)
{
print("ii0="+$ii0+"\n");
if ($ii0==1)
{
$target=$obj;
//print("target="+$target+"\n");
$ii0=2;
}
else
{
$dupO=`duplicate $target`;
$newObj=$dupO[0];
//print("new dup="+$newObj+"\n");

$prnO=`listRelatives -parent $obj`;
$theParent=$prnO[0];
parent -a $newObj $theParent;

$tx=eval("getAttr "+$obj+".translateX");
$ty=eval("getAttr "+$obj+".translateY");
$tz=eval("getAttr "+$obj+".translateZ");

$rx=eval("getAttr "+$obj+".rotateX");
$ry=eval("getAttr "+$obj+".rotateY");
$rz=eval("getAttr "+$obj+".rotateZ");

$sx=eval("getAttr "+$obj+".scaleX");
$sy=eval("getAttr "+$obj+".scaleY");
$sz=eval("getAttr "+$obj+".scaleZ");

eval("setAttr "+ $newObj+".translateX "+$tx);
eval("setAttr "+ $newObj+".translateY "+$ty);
eval("setAttr "+ $newObj+".translateZ "+$tz);

eval("setAttr "+ $newObj+".rotateX "+$rx);
eval("setAttr "+ $newObj+".rotateY "+$ry);
eval("setAttr "+ $newObj+".rotateZ "+$rz);

eval("setAttr "+ $newObj+".scaleX "+$sx);
eval("setAttr "+ $newObj+".scaleY "+$sy);
eval("setAttr "+ $newObj+".scaleZ "+$sz);

rename $newObj ("d_"+$obj);
delete $obj;

}

}
[/code]