Skip to content

Instantly share code, notes, and snippets.

@jm991
Last active October 30, 2017 04:39
Show Gist options
  • Save jm991/e9611f369c59e6139399207d9e899b7d to your computer and use it in GitHub Desktop.
Save jm991/e9611f369c59e6139399207d9e899b7d to your computer and use it in GitHub Desktop.
Find out which camera you are working with
//---------------------------------------------------------------------------------
// Source: https://acaciaecho.wordpress.com/2011/08/05/maya-get-current-camera/
// Author: Zhang Jian
// Date: 08-05-2011
//
// Description:
// Find out which camera you are working with. Focus on a model panel,
// in which you can have a camera to tumble/pan/zoom, and run getCurrentCamera,
// you will have the transform name of the camera.
// If you are in some other type of panel, say outliner, empty string will be returned.
// Installation:
// 1. Copy getCurrentCamera.mel to C:\Users\[USER]\Documents\maya\[MAYAVERSION]\prefs\scripts\jm991
// 2. Restart maya
global proc string getCurrentCamera()
{
string $camera;
// First get the panel that currently has focus
string $panel = `getPanel -wf`;
// Compare the panel's type to confirm it is a "modelPanel"
if ( "modelPanel" == `getPanel -to $panel` )
{
// Get the name of the camera using the ‘modelEditor’ command
$camera = `modelEditor -q -camera $panel`;
}
if($camera == "")
return "";
if(`nodeType $camera` == "camera")
{
string $rels[] = `listRelatives -p $camera`;
$camera = $rels[0];
}
return $camera;
}
@jm991
Copy link
Author

jm991 commented Oct 30, 2017

Remove the ".c" from the filename when you download this (git doesn't support .mel syntax highlighting)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment