Code:
///////////////////////////////
{
// For this example I'm hardcoding the new camera's name as a pre-existing "camera1"
// The new camera will have keyframes set in the order that you've selected the "old" cameras
string $cameraList[] = `ls -sl`;
if(`size($cameraList)`>0){
string $newCam = "camera1";
float $camPosition[];
float $camRotation[];
string $keyableTrans[] = {".tx", ".ty", ".tz"};
string $keyableRot[] = {".rx", ".ry", ".rz"};
float $existingKeys[];
for($cam in $cameraList){
// Get the position, rotation and existing keys of camera
$camPosition = `xform -query -translation $cam`;
$camRotation = `xform -query -rotation $cam`;
$existingKeys = `keyframe -q $cam`;
// Apply that transformation info to new camera
xform -translation $camPosition[0] $camPosition[1] $camPosition[2] $newCam;
xform -rotation $camRotation[0] $camRotation[1] $camRotation[2] $newCam;
// Set a keyframe on new camera's translation and rotation channels
// at the frame specified by the first keyframe found in old cam's $existingKeys
for($transChannel in $keyableTrans){
if(`getAttr -keyable ($newCam + $transChannel)` || `getAttr -channelBox ($newCam + $transChannel)`)
setKeyframe -time $existingKeys[0] ($newCam + $transChannel);
}
for($rotChannel in $keyableRot){
if(`getAttr -keyable ($newCam + $rotChannel)` || `getAttr -channelBox ($newCam + $rotChannel)`)
setKeyframe -time $existingKeys[0] ($newCam + $rotChannel);
}
}
}
}
//////////////////////////////
Hope that helps!