Switching Perspective Window Between Different Cameras

Hello,

Is it possible to switch active camera in perspective window from MEL? I'm talking about: Panels->Perspective->SomeCam. I don't see anything going on in script editor when I do this and failed to find info about that in docs as well.

Basically I want to make some small compositing right in the preview window is there any better/suitable way?

Thank you!

CODE
lookThroughModelPanel perspShape modelPanel4;

The modelPanel number will depend on the layout you are using.

Stev

You don't need to use "Shape" as part of the camera name.

CODE
lookThroughModelPanel persp modelPanel2;

Coincidently, I was exploring camera manipulation earlier today - you might find this useful:
Here is a script which will open a floating window with a camera viewport. The script uses a camera named audienceCam, but you could substitute the name of any camera in your scene.CODE
{
    if ( window -exists Audience ){
        if ( window -q -vis Audience ){
            window -e -vis 0 Audience;
        } else {
            window -e -vis 1 Audience;
        }
    } else {
        // If the window doesn't exist, create it
        window -retain Audience; //-tlc is topLeftCorner, -wh is widthHeight
        paneLayout;// Attach Panel to window
        string $curModelPanel = modelPanel "audienceCam";// Note that if executed w/out variable assigment, the panel name is not created.
        lookThroughModelPanel AudienceCam audienceCam;// Look thru camName camPanelName
        modelEditor -e -da "smoothShaded" -displayTextures on  -allObjects 0  -polymeshes 1  -nurbsCurves 1  -nurbsSurfaces 1 -gr off -sel off audienceCam;// da is -displayAppearance
        showWindow;
    }
    }
If you execute the script mulitple times, it will toggle the visibility of the window. If you close the window, the script will reopen it and I think it will be saved with your scene.

Note that this script creates a window and a model panel, to remove them from your scene, you would use this code:CODE
if(window -exists Audience ){deleteUI -window Audience;};
    if(panel -exists audienceCam){deleteUI  -pnl audienceCam;};

FYI: You can MMB-drag a cam from the outliner to the viewport to have the cam activated!

furthermore you can get the panel under the cursor with:

CODE
getPanel -wf
and you can switch the cam directly at a modelPanel:
CODE
modelPanel -e -cam persp modelPanel4;
so you could do for instance:

CODE
{
     string $thisPanel = getPanel -wf;
     if (getPanel -to $thisPanel == "modelPanel")
     {
         string $cams[] = listRelatives("-p", ls -cameras);
         string $activeCam = modelPanel -q -cam $thisPanel;
         int $switchToCam;
         for ($i = 0; $i < size($cams); $i++)
         {
             if ($activeCam == $cams[$i])
             {
                 $switchToCam = $i + 1;
                 break;
             }
         }
         if ($switchToCam >= size($cams))
             $switchToCam = 0;

         modelPanel -e -cam $cams[$switchToCam] $thisPanel;
     }
}
browse the cams in the current panel. You could even exclude certain cams from the array before you loop it..

That's interesting - alway good to see how to use the code.
Thanks.