# Switching Perspective Window Between Different Cameras

**URL:** https://forum.highend3d.com/t/switching-perspective-window-between-different-cameras/1477
**Category:** Maya
**Tags:** mel
**Created:** [May 30, 2008, 9:54pm UTC](https://forum.highend3d.com/t/switching-perspective-window-between-different-cameras/1477 "2008-05-30T21:54:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![\_dk\_](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/_/ba9def/32.png) [@\_dk\_](https://forum.highend3d.com/u/_dk_)
#### Post date: [May 30, 2008, 9:54pm UTC](https://forum.highend3d.com/t/switching-perspective-window-between-different-cameras/1477/1 "2008-05-30T21:54:02Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![skalinow](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@skalinow](https://forum.highend3d.com/u/skalinow)
#### Post date: [May 31, 2008, 1:21am UTC](https://forum.highend3d.com/t/switching-perspective-window-between-different-cameras/1477/2 "2008-05-31T01:21:53Z")

</div>

CODE  
lookThroughModelPanel perspShape modelPanel4;

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

Stev

---

<div class="post-metadata">

### Author: ![pixl](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pixl](https://forum.highend3d.com/u/pixl)
#### Post date: [May 31, 2008, 5:23am UTC](https://forum.highend3d.com/t/switching-perspective-window-between-different-cameras/1477/3 "2008-05-31T05:23:42Z")

</div>

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  
 {  
&nbsp;&nbsp;&nbsp;&nbsp;if ( `window -exists Audience` ){  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( `window -q -vis Audience` ){  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window -e -vis 0 Audience;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window -e -vis 1 Audience;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;} else {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// If the window doesn't exist, create it  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window -retain Audience; //-tlc is topLeftCorner, -wh is widthHeight  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paneLayout;// Attach Panel to window  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $curModelPanel = `modelPanel "audienceCam"`;// Note that if executed w/out variable assigment, the panel name is not created.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lookThroughModelPanel AudienceCam audienceCam;// Look thru camName camPanelName  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modelEditor -e -da "smoothShaded" -displayTextures on&nbsp;&nbsp;-allObjects 0&nbsp;&nbsp;-polymeshes 1&nbsp;&nbsp;-nurbsCurves 1&nbsp;&nbsp;-nurbsSurfaces 1 -gr off -sel off audienceCam;// da is -displayAppearance  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showWindow;  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;}  
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;};  
&nbsp;&nbsp;&nbsp;&nbsp;if(`panel -exists audienceCam`){deleteUI&nbsp;&nbsp;-pnl audienceCam;};

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [May 31, 2008, 9:20am UTC](https://forum.highend3d.com/t/switching-perspective-window-between-different-cameras/1477/4 "2008-05-31T09:20:59Z")

</div>

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  
{  
&nbsp;&nbsp;&nbsp;&nbsp; string $thisPanel = `getPanel -wf`;  
&nbsp;&nbsp;&nbsp;&nbsp; if (`getPanel -to $thisPanel` == "modelPanel")  
&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $cams[] = listRelatives("-p", `ls -cameras`);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $activeCam = `modelPanel -q -cam $thisPanel`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int $switchToCam;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($i = 0; $i \< size($cams); $i++)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($activeCam == $cams[$i])  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $switchToCam = $i + 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($switchToCam \>= size($cams))  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $switchToCam = 0;

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

---

<div class="post-metadata">

### Author: ![pixl](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pixl](https://forum.highend3d.com/u/pixl)
#### Post date: [June 6, 2008, 10:34pm UTC](https://forum.highend3d.com/t/switching-perspective-window-between-different-cameras/1477/5 "2008-06-06T22:34:20Z")

</div>

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