[Maya]Align Camera to current view - script for Maya

Please feel free to add your own scripts that you find useful for 3ds MAX and/or Maya!
Post Reply
Carl Buhre
Quality Assurance Consultant
Posts: 438
Joined: Mon Feb 25, 2008 12:59 pm
Location: Gothenburg, Sweden
Contact:

[Maya]Align Camera to current view - script for Maya

Post by Carl Buhre » Fri Dec 12, 2008 1:30 pm

Align Camera to current view - script for Maya

This is a very useful script when working with cameras in Maya. It moves the selected camera to your current view and parents it to that camera (except when it's the persp-camera).
Usage: Select the camera you want to move to the current view

Code: Select all

{
// Author: Luigi Tramontana @ Craft Animations
// MCP: Move Camera and Parent selected camera
// Usage: Select the camera you want to move to the current view

string $currPanel = `getPanel -withFocus`;
string $currCamera = `modelPanel -q -camera $currPanel`; 
// Save the current position of the current camera.
string $homeName = `cameraView -camera $currCamera`;
// Get selection list. Gets listed in the selection order.
string $nodes[] = `ls -selection`;
if( `camera -q -orthographic $currCamera` == 0) // if not orthographic continue
{
                // Make the selected camera identical to the current view.
                cameraView -e -camera $nodes[0] -sc $homeName;
                // Look through the selected camera.
                lookThroughModelPanel $nodes[0] $currPanel; //lookThroughModelPanelClipped $nodes[0] $currPanel 0.001 1000;
                if( `strcmp $currCamera persp` != 0) // if not persp camera, parent selected camera to it
                {
                                // Parent the selected camera to the current.
                                parent $nodes[0] $currCamera;
                }
}
};
You can select the script text in the Script Editor and drag it to a shelf spot to create a shortcut for it. Select MEL when prompted for MEL/Python.

footy_at_ubisoft
Posts: 2
Joined: Fri Mar 04, 2011 2:51 pm

Re: [Maya]Align Camera to current view - script for Maya

Post by footy_at_ubisoft » Fri Mar 04, 2011 2:57 pm

Hi,
I cannot seem to get this script to function as I would expect. I copied this into the script editor. And I made a toolbar shelf icon.
But after that I don't know what to do. Should I click on child, then Parent, then hit the toolbar? Doing this provides an error: // Error: modelPanel: Object 'outlinerPanel1' not found.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests