March 2019: ewertb.soundlinker.com is getting relocated to ewertb.mayasound.com, please update your bookmarks.

MEL How-To #19

Back · Previous · Next Maya

How can I determine if a camera other than the default cameras has been created if I don't know the name of the new camera?

By default Maya creates four cameras for a scene:

persp
front
side
top

The first camera, ‘persp’ is non-orthographic, the remaining three are orthographic.

It is not possible (without effort) to rename or delete these default cameras as they are flagged as read-only. You can determine if a camera is read-only -- or rather if it's flagged as one of the default startup cameras -- by querying the ‘−startupCamera’ flag using the ‘camera’ command:

camera -q -startupCamera persp;
// Result: 1 //

Knowing this, it is possible to get a list of all cameras, query each for the ‘−startupCamera’ flag, and mark any others as a camera that the user has added.

proc string[] getExtraCameras()
{
  string $extraCameras[];
  int $numExtraCameras = 0;

  string $cameras[] = `ls -cameras`;

  for ( $camera in $cameras )
  {
    // If this camera is not a startupCamera, add it to the array
    if ( !`camera -q -startupCamera $camera` )
      $extraCameras[$numExtraCameras++] = $camera;
  }

  return $extraCameras;
}

// Get a list of all non-startup cameras
string $extraCameras[] = getExtraCameras();

if ( size( $extraCameras ) )
{
  print ( "The following cameras have been added to the scene:\n" );
  print $extraCameras;
}
else
  print ( "No extra cameras added to the scene.\n" );