Hey RFlannery, thanks for the reply.
I don’t think i explained properly what i’d already tried, so my bad there, but i’v already gone through the process you’ve described and come up with nothing. I got to the last line, and if i delete it and retype exactly as it was, then the script works when i run it. It seems to me like the act of editing it in the script editor does something which allows it to run, but once i save it out as a mel file and try to run the procedure either in the script editor or through a hotkey/shelf item in a freshly opened maya, it just crashes. Even simply adding a new comment to the script allows it to run in that instance of maya, but on a new instance its back to crashing.
Heres the script if it helps:
//compare camera name strings, matching string = 0, otherwise 1 or -1
//does cam exist boolean set to true on match, returns int value
proc int doesCamExist (string $camName)
{
string $cameraList[] = `listCameras`;
int $doesCamExist = false;
for ($camera in $cameraList)
{
$compare = `strcmp $camName $camera`;
if ($compare == 0)
{
$doesCamExist = true;
break;
}
}
return $doesCamExist;
}
//check if an orthographic camera already exists for desired view
//if true, use existing caera, if false create new camera
proc camCheck (string $camStruct[])
{
if (size($camStruct) > 1)
{
string $camName = $camStruct[0];
string $axis = $camStruct[1];
int $camCheck = doesCamExist($camName);
if ($camCheck == 1)
{
lookThru $camName;
print ($camName + " camera exists - using existing camera");
}
else if ($camCheck == 0)
{
camera;
rename "camera1" $camName;
camera -e -o 1 -ncp 0.001 -fcp 10000 $camName;
lookThru $camName;
viewAlongAxis modelPanel4 $axis;
modelEditor -e -twoSidedLighting true modelPanel4;
print ($camName + " camera doesnt exist - creating new camera");
}
}
}
//if rotations go beyond 360, fix with modulus
//if rotations are negative, fix by adding 360
proc float fixRotation (float $Rot)
{
$fixedRot = $Rot % 360;
if ($fixedRot < 0)
{
$fixedRot += 360;
}
return $fixedRot;
}
//main function to switch between perspective and orthographic views based on camera orientation
global proc perspToOrtho ()
{
$currentCam = `lookThru -q`;
$camRot = `camera -q -rot persp`;
$xValue = fixRotation($camRot[0]);
$yValue = fixRotation($camRot[1]);
//check if camera is perspective, if not switch to perspective
if ($currentCam != "persp")
{
lookThru persp;
}
//check if top camera
else if ($xValue <= 315 && $xValue >= 225)
{
camCheck({"top", "-Y"});
setAttr "top.translateX" 0;
setAttr "top.translateY" 5;
setAttr "top.translateZ" 0;
}
//check if bottom camera
else if ($xValue >= 45 && $xValue <= 135)
{
camCheck({"bottom", "Y"});
setAttr "bottom.translateX" 0;
setAttr "bottom.translateY" -5;
setAttr "bottom.translateZ" 0;
}
//check if front camera
else if ( ($yValue <= 45 && $yValue >= 0) || ($yValue >= 315 && $yValue <= 360) )
{
camCheck({"front", "-Z"});
setAttr "front.translateX" 0;
setAttr "front.translateY" 0;
setAttr "front.translateZ" 5;
}
//check if back camera
else if ($yValue >= 135 && $yValue <= 225)
{
camCheck({"back", "Z"});
setAttr "back.translateX" 0;
setAttr "back.translateY" 0;
setAttr "back.translateZ" -5;
}
//check if left camera
else if ($yValue > 225 && $yValue < 315)
{
camCheck({"left", "X"});
setAttr "left.translateX" -5;
setAttr "left.translateY" 0;
setAttr "left.translateZ" 0;
}
//check if right camera
else if ($yValue > 45 && $yValue < 135)
{
camCheck({"right", "-X"});
setAttr "right.translateX" 5;
setAttr "right.translateY" 0;
setAttr "right.translateZ" 0;
}
else
{
print "error: no valid camera choice from current values";
}
}