Horganovski
11-09-2010, 04:37 PM
Hey Folks,
First time posting here, I'm a C4D user taking 1st steps with Maya, as a little crash course I've been trying to reproduce a little script I use in C4D to help mirror hip/spine/head poses for characters when building walkcycles etc.
This is a generic script that doesn't need to be added to a rig, to use it I just select the objects and run it and it will mirror the translate X and rotate Y and Z.
It almost works fine, but I've run into one situation that I can't find a solution for yet :
If I use this on a rig where some of the translate channels (say the position for FK controllers in the spine for example) are locked, the script will fail as it returns an error that it can't 'setAttr' for this channel. Is there a way I can tell it to either ignore the error and keep going setting the other coordinates, or can I build in a little check to see if the channel is locked before trying to set the attribute?
Any ideas much appreciated, here's the existing code (my 1st Mel script! : ) )
I'm sure this could be a lot more efficient in places, but I'm just trying to get the basics working right now.
string $sel[] = `ls -sl`; int $selCount = size($sel);
print("Number of selected object(s) is " + $selCount);
if ($selCount == 1) {
vector $pos = getAttr($sel[0] + ".translate");
vector $rot = getAttr($sel[0] + ".rotate");
string $object = $sel[0];
float $xPos = $pos.x;
float $yPos = $pos.y;
float $zPos = $pos.z;
float $xRot = $rot.x;
float $yRot = $rot.y;
float $zRot = $rot.z;
$xPos = $xPos *-1;
$yRot = $yRot *-1;
$zRot = $zRot *-1;
print($object);
setAttr ($object+ ".rx") ($xRot);
setAttr ($object+ ".ry") ($yRot);
setAttr ($object+ ".rz") ($zRot);
setAttr ($object+ ".tx") ($xPos);
setAttr ($object+ ".ty") ($yPos);
setAttr ($object+ ".tz") ($zPos);
}
else {
for ($rc = 0; $rc <= size($sel); $rc++) {
vector $pos = getAttr($sel[$rc] + ".translate");
vector $rot = getAttr($sel[$rc] + ".rotate");
string $object = $sel[$rc];
float $xPos = $pos.x;
float $yPos = $pos.y;
float $zPos = $pos.z;
float $xRot = $rot.x;
float $yRot = $rot.y;
float $zRot = $rot.z;
$xPos = $xPos *-1;
$yRot = $yRot *-1;
$zRot = $zRot *-1;
print($object);
setAttr ($object+ ".rx") ($xRot);
setAttr ($object+ ".ry") ($yRot);
setAttr ($object+ ".rz") ($zRot);
setAttr ($object+ ".tx") ($xPos);
setAttr ($object+ ".ty") ($yPos);
setAttr ($object+ ".tz") ($zPos);
}
}
Cheers,
Brian
First time posting here, I'm a C4D user taking 1st steps with Maya, as a little crash course I've been trying to reproduce a little script I use in C4D to help mirror hip/spine/head poses for characters when building walkcycles etc.
This is a generic script that doesn't need to be added to a rig, to use it I just select the objects and run it and it will mirror the translate X and rotate Y and Z.
It almost works fine, but I've run into one situation that I can't find a solution for yet :
If I use this on a rig where some of the translate channels (say the position for FK controllers in the spine for example) are locked, the script will fail as it returns an error that it can't 'setAttr' for this channel. Is there a way I can tell it to either ignore the error and keep going setting the other coordinates, or can I build in a little check to see if the channel is locked before trying to set the attribute?
Any ideas much appreciated, here's the existing code (my 1st Mel script! : ) )
I'm sure this could be a lot more efficient in places, but I'm just trying to get the basics working right now.
string $sel[] = `ls -sl`; int $selCount = size($sel);
print("Number of selected object(s) is " + $selCount);
if ($selCount == 1) {
vector $pos = getAttr($sel[0] + ".translate");
vector $rot = getAttr($sel[0] + ".rotate");
string $object = $sel[0];
float $xPos = $pos.x;
float $yPos = $pos.y;
float $zPos = $pos.z;
float $xRot = $rot.x;
float $yRot = $rot.y;
float $zRot = $rot.z;
$xPos = $xPos *-1;
$yRot = $yRot *-1;
$zRot = $zRot *-1;
print($object);
setAttr ($object+ ".rx") ($xRot);
setAttr ($object+ ".ry") ($yRot);
setAttr ($object+ ".rz") ($zRot);
setAttr ($object+ ".tx") ($xPos);
setAttr ($object+ ".ty") ($yPos);
setAttr ($object+ ".tz") ($zPos);
}
else {
for ($rc = 0; $rc <= size($sel); $rc++) {
vector $pos = getAttr($sel[$rc] + ".translate");
vector $rot = getAttr($sel[$rc] + ".rotate");
string $object = $sel[$rc];
float $xPos = $pos.x;
float $yPos = $pos.y;
float $zPos = $pos.z;
float $xRot = $rot.x;
float $yRot = $rot.y;
float $zRot = $rot.z;
$xPos = $xPos *-1;
$yRot = $yRot *-1;
$zRot = $zRot *-1;
print($object);
setAttr ($object+ ".rx") ($xRot);
setAttr ($object+ ".ry") ($yRot);
setAttr ($object+ ".rz") ($zRot);
setAttr ($object+ ".tx") ($xPos);
setAttr ($object+ ".ty") ($yPos);
setAttr ($object+ ".tz") ($zPos);
}
}
Cheers,
Brian
