MEL help about camera lock


#1

Hi everyone,

           I would like to ask help about my script, if it possible. 
           
           This script would make a camera with a "camera lock" attribute which lock the translate and rotate attribute, if it had work. 
           
           But I don't know how continue this script, because in the expression part have an error.
// Error:                "      setAttr -lock true -keyable true {$currentCam + ".tx"};
"+ //
 // Error: Syntax error //
           If anyone can help, I would be greatful.
           
           Here is the code:
camera;
 string $selection[] = `ls -sl`;
             for ($cam in $selection);
             addAttr -ln "CameraLock"  -at "enum" -en "ON:OFF:" $cam;
             addAttr -ln "CameraPass"  -at long $cam;
              setAttr -e -keyable true ($cam + ".CameraLock");
             setAttr -e -keyable true ($cam + ".CameraPass");
              rename $cam "newCamera";
            
              expression -s ("int $a= newCamera.CameraLock;
"+
                            "newCamera.CameraPass=$a;
"+
                            "switch ($a) { 
"+
                            "  case 0: 
"+
                            "      string $camSelect[] = `ls -sl`;
"+
                            "      string $currentCam;
"+
                            "      for ($currentCam in $camSelect);
"+
                            "      {;
"+
                            "      setAttr -lock true -keyable true {$currentCam + ".tx"};
"+
                            "      setAttr -lock true -keyable true {$currentCam + ".ty"};
"+
                            "      setAttr -lock true -keyable true {$currentCam + ".tz"};
"+
                            "      setAttr -lock true -keyable true {$currentCam + ".rx"};
"+
                            "      setAttr -lock true -keyable true {$currentCam + ".ry"};
"+
                            "      setAttr -lock true -keyable true {$currentCam + ".rz"};
"+
                            "      setAttr -lock true -keyable true {$currentCam + ".centerOfInterest"};
"+
                            "      };
"+
                            "      break;
"+
                            "    case 1: 
"+
                            "      string $camSelect[] = `ls -sl`;
"+
                            "      string $currentCam;
"+
                            "      for ($currentCam in $camSelect);
"+
                            "      {;
"+
                            "      setAttr -lock false -keyable true {$currentCam + ".tx"};
"+
                            "      setAttr -lock false -keyable true {$currentCam + ".ty"};
"+
                            "      setAttr -lock false -keyable true {$currentCam + ".tz"};
"+
                            "      setAttr -lock false -keyable true {$currentCam + ".rx"};
"+
                            "      setAttr -lock false -keyable true {$currentCam + ".ry"};
"+
                            "      setAttr -lock false -keyable true {$currentCam + ".rz"};
"+
                            "      setAttr -lock false -keyable true {$currentCam + ".centerOfInterest"};
"+
                            "      };
"+
                            "      break;
"+
                            "} \r");

#2

Finally, I found the solution. I put a backslash before write a second quotation for a string. Like this.

expression -s (" “.tx” ")

And worked :slight_smile: