Maya Mel , getAttr , setAttr , gmatch , substituteAllString , help me pls to find mistake


#1

global proc string replace (string $name)

{

if ( `gmatch $name "C_L_"` == 1)
	$name = substituteAllString($name,"C_L_","C_R_");

if ( `gmatch $name "C_R_"` == 1)
	$name = substituteAllString($name,"C_R_","C_L_");

return $name;

}

proc set_ROT (string $ele)

{   

vector $ROT;

$ROT = `getAttr ($ele + ".rotate")`;	

    if ((`getAttr -l (replace($ele) + ".rotateX")` == 0)&&(`getAttr -l (replace($ele) + ".rotateY")` == 0)&&(`getAttr -l (replace($ele) + ".rotateZ")` == 0))

        {
         setAttr (replace($ele) + ".rotateX") ($ROT.x);
         setAttr (replace($ele) + ".rotateY") ($ROT.y);
         setAttr (replace($ele) + ".rotateZ") ($ROT.z);   
        }

}

proc set_TR (string $ele)

{
vector $TR;
    $TR = `getAttr ($ele + ".translate")`;	

    if ((`getAttr -l (replace($ele) + ".translateX")` == 0)&&(`getAttr -l (replace($ele) + ".translateY")` == 0)&&(`getAttr -l (replace($ele) + ".translateZ")` == 0))
        {
        setAttr (replace($ele) + ".translateX") ($TR.x);
        setAttr (replace($ele) + ".translateY") ($TR.y);
        setAttr (replace($ele) + ".translateZ") ($TR.z);    
        }
}

proc main ()

{
string $sllist[] = ls -sl;

for ($elem in $sllist)
{
    set_TR($elem);
    set_ROT($elem);
}

}

main ();

Help me pls , this piece of code dosen’t show errors in script editor any more but still do nothing. I have no idea where I made mistake =(
It had to duplicate translates and rotates from L\R Controller to R\L.
Thanks.


#2
if ( `gmatch $name "C_L_"` == 1) $name = substituteAllString($name,"C_L_","C_R_");

change it to

else if ( `gmatch $name "C_L_"` == 1) $name = substituteAllString($name,"C_L_","C_R_");

try it out. not sure if that helps