Maya Get Current Camera

Still a bit of maybe useful piece of MEL to 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.

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;


Filed under MEL

2 responses to “Maya Get Current Camera

  1. Kiernan

    How would one return a cameraShape instead of just the camera name?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s