Maya - Position Recorder


I created this tool to aid 3D animators with posing/layout hookups that span across multiple Maya scenes.

Language:

Mel Script

      Compatibility:

Autodesk Maya

Add this script as a MEL button to your Maya toolbar to launch a custom UI. This tool creates additional scripts that records the keyable attributes for all selected objects. Once the additional scripts are created they can be viewed/run from the right hand side of the UI.

Rules:


  • All records are stored in a preset folder. Which can be changed in the presets section. this folder must already exist.
  • Object names must be the same across all scenes. ( conflicting prefixes can be removed using my "Remove Namespace/Prefix" tool.)
  • The "Record" button only effects selected objects.
  • The "Run" button effect all objects.
  • Multiple records can be run at once.
  • Your scene must be saved.

///////////////////////////////////////////////////////////////
//-----------------Notes-----------------
//1. Target Directory must already exsist.
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
//Create Pre-sets
///////////////////////////////////////////////////////////////
global string $recordPath = "C:/Maya_PositionRecords/";
string $sceneName = `file -q -sn -shn`;
global float $AW = 0;

///////////////////////////////////////////////////////////////
//Procedures
///////////////////////////////////////////////////////////////

proc Refreshlist() { 			//Refreshes list of already recoded (external .mel scripts)
	global string $recordPath;
	textScrollList -e -removeAll playList;
	string $tempList[] = `getFileList -folder $recordPath -filespec "*.mel"`;
	for ($item in $tempList) {
		textScrollList -e -append $item playList;
	}
}

proc record(){   				//Records object attributes to external mel script

	//fetch globals
	global string $recordPath;
	global float $AW;
	global string $fileNameField;
	
	//queries file name field
	string $fileName = `scrollField -q -tx $fileNameField`;
	string $fullPath = ($recordPath+$fileName);
	
	//open text file   ("a" = append  "w"=write)
	$fileId = `fopen ($fullPath+".mel") a`;
	if ($AW == 0){
		$fileId = `fopen ($fullPath+".mel") a`;
	}
	else{
		$fileId = `fopen ($fullPath+".mel") w`;
	}

	// process selection
	string $selection[] = `ls -sl`;	
	for ($object in $selection){	
		
		//write check for object opening.
		fprint $fileId ("if (`objExists "+ $object + "`){" + "\n");
		
		//write set attribute command for visable & unlocked.
		string $Attributes[] = `listAttr -k`;  //gets keyable attributes
		for ($i in $Attributes){
			string $value = `getAttr ($object + "." + $i)`;
			fprint $fileId ("setAttr " + $object + "." + $i + " " + $value + ";" + "\n");
		}
		
		//write check for object closing.
		fprint $fileId ("}"+"\n");
	}

	// Close text File  
	fclose $fileId ;
}

proc runRecord(){ 				//Runs selected recorded Script

	//fetch globals
	global string $recordPath;
	global string $recordList;

	//gets name of selected object
	string $listSelection[] = (`textScrollList -q -selectItem $recordList`);
	
	//runs each list Item selected
	for ($item in $listSelection){
		string $listSelectionPath = ($recordPath+$item);

		//create Custom Command
		if (`runTimeCommand -q -ex launchSelected`) runTimeCommand -e -delete launchSelected;
		runTimeCommand - command ("source \""+$listSelectionPath+"\"") launchSelected;
		launchSelected;
	}
}


///////////////////////////////////////////////////////////////
//GUI
///////////////////////////////////////////////////////////////

// create GUI
if (`window -q -ex AttributeRecorder`) deleteUI AttributeRecorder;
string $window = `window 
		-bgc 0.15 0.15 0.15
		-title "Attribute Recorder"
		-widthHeight 500 200
		-sizeable true
		AttributeRecorder`;

//GUI Layout
rowColumnLayout -numberOfColumns 2 -columnWidth 1 200 -columnWidth 2 300;
	text -label "Created by: Liam M. Broughm";
	text -label " ";

	//record frame
	frameLayout -label "Record Attributes of Selected" -collapsable false;
		columnLayout;
			text -label "Save record as:";
			$fileNameField = `scrollField -wordWrap false -h 52 -w 196
				-text $sceneName -editable true`;
			text -label "If file already exists:";
			$AWradio = `radioCollection`;
				$A = `radioButton -label "Append to exsisting" -onCommand "$AW = 0"`;
				$W = `radioButton -label "Erase and re-write" -onCommand "$AW = 1"`;
			button -label "Record Selected" -bgc 0.3 0.3 0.3 -w 196 -command "record";
		setParent ..;
	setParent ..;

	//run frame
	frameLayout -label "Existing Records" -collapsable false;
		columnLayout;
			$recordList = `textScrollList -h 113 -w 296 -allowMultiSelection true playList`;
			rowColumnLayout -numberOfColumns 2 -columnWidth 1 100 -columnWidth 2 196;
				button -label "Refresh List" -bgc 0.3 0.3 0.3 -command "Refreshlist";
				button -label "Run Selected" -bgc 0.3 0.3 0.3 -command "runRecord";
		setParent ..;
	setParent ..;

	//Defalt Settings
	radioCollection -edit -select $A $AWradio;

showWindow $window;

Maya - Remove Namespace/Prefix


//floating Value of text field.
proc NamespaceBTN()
{
	global string $prefixField;
	string $v = `textField -q -tx $prefixField`;

	//create Custom Command
	if (`runTimeCommand -q -ex CustomCommand`) runTimeCommand -e -delete CustomCommand;
	runTimeCommand - command ("namespace -mv \""+$v+"\" \":\" -force;") CustomCommand;
	CustomCommand;
}
proc PrefixBTN()
{
	global string $prefixField;
	string $v = `textField -q -tx $prefixField`;
	string $pasted[] = `ls ($v+"*")`;
	string $object;
	for ( $object in $pasted )
	{
		string $elements[];
		tokenize( $object, "|", $elements );
		string $stripped = $elements[ `size $elements` - 1 ];

		$stripped = `substitute ($v) $stripped ""`;

		catchQuiet(`evalEcho("rename " + $object + " " + $stripped)`);
	}
}

global string $prefixField;

//clears window if it is already open
if (`window -q -ex NamespaceWindowUI`) deleteUI NamespaceWindowUI;

// create a window
	window -bgc 0.15 0.15 0.15 -title "Namespace removal" -sizeable true NamespaceWindowUI;
		columnLayout;
			frameLayout -label "Namespace Removal";
				columnLayout;
					$prefixField = `textField -w 150`;
					button -bgc 0.3 0.3 0.3 -label "Remove Namespace" -w 150 -command "NamespaceBTN";
					button -bgc 0.3 0.3 0.3 -label "Remove Prefix" -w 150 -command "PrefixBTN";

				setParent ..;
			setParent ..;
			text -label "Created by Liam M. Broughm";
	// show the window we last created
showWindow NamespaceWindowUI;

Camera Timecode


//set framerate
float $frameRate = 30;

//get current frame
$frame = `currentTime -q`;

//Frame with padding
string $padFrame = "0";
if ($frame < 1){
	$padFrame = "0000";
}
else if ($frame < 10){
	$padFrame = ("000"+$frame);
}
else if ($frame < 100){
	$padFrame = ("00"+$frame);
}
else if ($frame < 1000){
	$padFrame = ("0"+$frame);
}
else{
	$padFrame = $frame;
}

//Time code values
	$fra = $frame;
	int $sec = ($fra/$frameRate);
	int $min = ($sec/60);
	int $hour = ($min/60);
	int $displayFra = ($fra-($sec*$frameRate));
	int $displaySec = ($sec-($min*60));
	int $displayMin = ($min-($hour*60));

//Time Code Padding
	//Code fra
	string $codeFra = "0";
	if ($displayFra < 1){
		$codeFra = "00";
	}
	else if ($displayFra < 10){
		$codeFra = ("0"+$displayFra);
	}
	else{
		$codeFra = $displayFra;
	}

	//Code sec
	string $codeSec = "0";
	if ($displaySec < 1){
		$codeSec = "00";
	}
	else if ($displaySec < 10){
		$codeSec = ("0"+$displaySec);
	}
	else{
		$codeSec = $displaySec;
	}


	//Code Min
	string $codeMin = "0";
	if ($displayMin < 1){
		$codeMin = "00";
	}
	else if ($displayMin < 10){
		$codeMin = ("0"+$displayMin);
	}
	else{
		$codeMin = $displayMin;
	}

	//Code Hour
	string $codeHour = "0";
	if ($hour < 1){
		$codeHour = "00";
	}
	else if ($hour < 10){
		$codeHour = ("0"+$hour);
	}
	else{
		$codeHour = $hour;
	}

//time Code Full
string $timeCode = ($codeHour+":"+$codeMin+":"+$codeSec+":"+$codeFra);


// get the global frame number as a string
string $annotationText = ($timeCode+"    fr:("+$padFrame+")");

// set it to FrameCountShape.text attribute
setAttr -type "string" FrameCountShape.text $annotationText;

//sceneInfoShape.displayArrow = 0;


  • Mailing Address

    49 Clermont Cres.
    Dartmouth, Nova Scotia,
    B2W 4N9

  • Mobile

    902 222-9003


  • Email

    liam@lbroughm.com


  • Copyright ©

    Liam Broughm,

    All Rights Reserved.