View Single Post
# 2 20-09-2017 , 09:27 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
It would simply be a case of selecting all the cameras and saving that list to a variable. Using a "for loop", you can cycle through the camera list and grab their position in 3D space and use those coordinates to set keyframes on the a new camera (which you can create beforehand or have the script do it that too)

So essentially...
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!


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::