Thursday, September 25, 2008

AnimationTraxUI

This is a helpful little UI that will allow the animator keep multiple animations organized within a single maya file. It saves the name of the animation, and the start and end time, and automatically adjusts the time slider to match the times of the anim after being set by the animator. It also has an export function to export the selected anim to a .anim file.



//This UI will set up a UI to manage note tracks for animations.

global proc AnimationTraxUI ()
{
//initial window setup
if (`window -exists AnimationTraxUI`)
deleteUI AnimationTraxUI;

window
-t "Animation Trax"
-wh 500 325
-mxb off
-resizeToFitChildren on
-sizeable off
AnimationTraxUI;

columnLayout -adj 1 imageCol;
string $baseImageDir = `getenv "ACOOK_SCRIPT_PATH"` + "/Icons/AnimationTraxUI/";
image -w 500 -h 20 -image ($baseImageDir + "logo.tif");

separator -w 500 -style "in";

formLayout animForm;
//content start
text -l "Animations:" animText;
text -l "Notes:" noteText;

textScrollList -h 150 TSLanims;
textScrollList -h 150 TSLnotes;

button -l "New Anim" -command "addNewAnim" newAnimButton;
button -l "Start Time" -command "addStartTime" startAnimButton;
button -l "End Time" -command "addEndTime" endAnimButton;
button -l "Event" -command "eventTrigger" eventButton;
button -l "Export" -command "export" exportAnimButton;

popupMenu -parent TSLanims;
menuItem -l "Delete Anim" -command "deleteAnim ()";
popupMenu -parent TSLnotes;
menuItem -l "Delete Note";
//content end

//UI layout formation
formLayout -e
-af animText top 0
-af animText left 0
-ap animText right 0 45

-af noteText top 0
-ac noteText left 0 animText
-af noteText right 0

-ac TSLanims top 0 animText
-af TSLanims left 0
-ap TSLanims right 0 45

-af TSLnotes right 0
-ac TSLnotes top 0 noteText
-ac TSLnotes left 2 TSLanims
-aoc TSLnotes bottom 0 TSLanims

-ac newAnimButton top 5 TSLanims
-af newAnimButton left 0
-ap newAnimButton right 0 45

-ac startAnimButton top 5 TSLnotes
-ac startAnimButton left 2 newAnimButton
-ap startAnimButton right 0 63

-ac endAnimButton top 5 TSLnotes
-ac endAnimButton left 0 startAnimButton
-ap endAnimButton right 0 81

-ac eventButton top 5 TSLnotes
-ac eventButton left 0 endAnimButton
-ap eventButton right 0 100

-af exportAnimButton left 20
-ac exportAnimButton top 5 newAnimButton
-ap exportAnimButton right 0 40

animForm;

separator -w 500 -style "in";

setParent imageCol;
string $collapse = "window -e -h 295 AnimationTraxUI";
string $expand = "window -e -h 500 AnimationTraxUI";

frameLayout -collapsable 1
-label "Help"
-collapse on
-borderStyle "etchedIn"
-marginHeight 2
-marginWidth 2
-collapseCommand $collapse
-expandCommand $expand
helpFrame;

columnLayout helpCol;

string $help;

$help = ("Start by clicking the New Anim Button, then select the frame you want that anim to start at"
+"and click Start Time.\n\nRepeat for the End time of the animation.\n"
+"Create the start frame first, otherwise when you create the start frame it will overwrite your first note.\n"
+"Add events in the middle of the animation the same way as the start and end time.\n\n"
+"To delete an animation or note, simply right click on the anim or note and "
+"select 'Delete Anim' or 'Delete Note.'\nThis functionality will be implemented soon.\n\n"
+"Any questions, comments, or suggestions \nemail me at jalek_99@yahoo.com.\n\n"
+"Thanks,\n"
+"Andrew Cook");

scrollField
-ed false
-wordWrap true
-text $help
-w 492
-h 200
helpScrollField;
//End of Layout Formation

showWindow AnimationTraxUI;

FillAnims;

}

global proc FillAnims()
{
string $animNameString[] = `fileInfo -q SavedAnimations`;
string $animNames[];
$animNames = stringToStringArray( $animNameString[0], "|" );

if (size($animNames) == 0)
print "Please create an animation.\n";
else
{
string $selAnim[] = `textScrollList -q -si TSLanims`;
string $allAnims[] = `textScrollList -q -ai TSLanims`;
string $allNotes[] = `textScrollList -q -ai TSLnotes`;
string $newStartTimeName = "Start";
textScrollList -e -ra TSLanims;
// Fill the animation scroll list with the animation names
for ($eachAnim in $animNames)
{
textScrollList -e
-append $eachAnim
-si $animNames[0]
-sc "AnimSelected"
TSLanims;
}
/*
for ($eachNote in $allNotes)
{
textScrollList -e -append $eachNote TSLnotes;
}
textScrollList -e -si $newStartTimeName TSLnotes; */
// Call NoteSelected if it doesn't automatically get called
fillNotes();
}
}

//Populate the Notes TSL

global proc fillNotes()
{
string $allNotes[] = `textScrollList -q -ai TSLnotes`;
string $selAnim[] = `textScrollList -q -selectItem TSLanims`;
textScrollList -e -ra TSLnotes;

string $varName = $selAnim[0] + ".Events";
string $animEventsString[] = `fileInfo -q $varName`;
string $animEvents[] = stringToStringArray( $animEventsString[0], "|" );

for ( $eachEvent in $animEvents )
{
string $eventNames[] = stringToStringArray( $eachEvent, "." );
int $i = 1;
string $eventName = "";
for ( $i; $i <> 1 )
{
$eventName = $eventName + ".";
}
$eventName = $eventName + $eventNames[$i];
}
textScrollList -e -append $eventName TSLnotes;
}

textScrollList -e
-selectItem "Start"
-sc "NoteSelected"
TSLnotes;
}

//----------------------------
// Add new anim

global proc addNewAnim ()
{
string $newAnimName;
string $newAnim;

string $result = `promptDialog
-title "New Anim"
-message "Enter New Anim Name:"
-button "Ok" -button "Cancel"
-defaultButton "Ok" -cancelButton "Cancel"
-dismissString "Cancel"`;

string $allAnims[] = `textScrollList -q -ai TSLanims`;

if ($result == "Ok")
{
$newAnimName = `promptDialog -query -text`;
$newAnim = $newAnimName;
$allAnims[size($allAnims)]=$newAnim;
$allAnims=sort($allAnims);
string $allAnimsString = stringArrayToString( $allAnims, "|" );
fileInfo SavedAnimations $allAnimsString;


textScrollList -e -ra TSLanims;

for ($eachAnim in $allAnims)
textScrollList -e -a $eachAnim TSLanims;
//select the just created Anim.
textScrollList -e -si $newAnim TSLanims;
//also, clear the note track for the new anim.
textScrollList -e -ra TSLnotes;
textScrollList -e -selectCommand "AnimSelected ()" TSLanims;
}
else if (size($allAnims) > 0)
{
textScrollList -e -si $allAnims[0] TSLanims;
}
else
{
print "Please create an animation.\n";
}
}

//----------------------------
// Add Start Time for selected anim

global proc addStartTime ()
{
string $selAnim[] = `textScrollList -q -si TSLanims`;
string $allAnims[] = `textScrollList -q -ai TSLanims`;
string $allNotes[] = `textScrollList -q -ai TSLnotes`;

string $newStartTimeName = "Start";
int $newStartTime;

string $result = `confirmDialog
-title "Start Time"
-message "Create or Move start time to the selected frame?"
-button "Ok" -button "Cancel"
-defaultButton "Ok"
-cancelButton "Cancel"
-dismissString "Cancel"`;

if ($result == "Ok")
{
$newStartTime = `currentTime -query`;
playbackOptions -min $newStartTime;

string $startVariableName = $selAnim[0] + "." + $newStartTimeName;
fileInfo $startVariableName $newStartTime;
//add NewStartTime to the TOP of the list
$allNotes[0] = $newStartTimeName;
//clear TSLnotes for repopulation
textScrollList -e -ra TSLnotes;
//repopulate TSLnotes
for ($eachNote in $allNotes)
textScrollList -e -append $eachNote TSLnotes;
textScrollList -e -si $newStartTimeName TSLnotes;
}
saveEventNames();
}

//----------------------------------
// Add End Time

global proc addEndTime ()
{
string $selAnim[] = `textScrollList -q -si TSLanims`;
string $allAnims[] = `textScrollList -q -ai TSLanims`;
string $allNotes[] = `textScrollList -q -ai TSLnotes`;

string $newEndTimeName = "End";
int $newEndTime;

string $result = `confirmDialog
-title "Start Time"
-message "Create or Move End time to the selected frame?"
-button "Ok" -button "Cancel"
-defaultButton "Ok"
-cancelButton "Cancel"
-dismissString "Cancel"`;

if ($result == "Ok")
{
$newEndTime = `currentTime -query`;
playbackOptions -max $newEndTime;

// Save the end time variable to the scene
string $endVariableName = $selAnim[0] + "." + $newEndTimeName;
fileInfo $endVariableName $newEndTime;
if (size($allNotes) > 1)
{
//if there is an end note, change it.
$allNotes[size ($allNotes) - 1] = $newEndTimeName;
}
else
{
//or add it if there isn't one.
$allNotes[size ($allNotes)] = $newEndTimeName;
}

//clear TSLnotes for repopulation
textScrollList -e -ra TSLnotes;

//repopulate TSLnotes
for ($eachNote in $allNotes)
textScrollList -e -append $eachNote TSLnotes;
textScrollList -e -si $newEndTimeName TSLnotes;
}
saveEventNames();
}

//-------------------------------------
//Proc for when a note is selected in the window
global proc NoteSelected ()
{
string $selAnim[] = `textScrollList -q -si TSLanims`;
string $selNote[] = `textScrollList -q -si TSLnotes`;
string $allNotes[] = `textScrollList -q -ai TSLnotes`;

if (size($allNotes) > 0)
{
string $varName = ($selAnim[0] + "." + $selNote[0]);
string $variableValue[] = `fileInfo -q $varName`;
currentTime $variableValue[0];
}
// else print "Please create a start and end time for the animation.\n";
}

//------------------------------------
// Proc for when an anim is selected in the window

global proc AnimSelected ()
{
string $selAnim[] = `textScrollList -q -si TSLanims`;
string $selNote[] = `textScrollList -q -si TSLnotes`;
string $allNotes[] = `textScrollList -q -ai TSLnotes`;

string $varName = ($selAnim[0] + "." + $selNote[0]);
string $variableValue[] = `fileInfo -q $varName`;

textScrollList -e -si $allNotes[0] TSLnotes;

$varName = ($selAnim[0] + ".Start");
string $startTime[] = `fileInfo -q $varName`;
playbackOptions -min $startTime[0];

$varName = ($selAnim[0] + ".End");
string $endTime[] = `fileInfo -q $varName`;
playbackOptions -max $endTime[0];

fillNotes;
NoteSelected;

if (size($allNotes) == 0)
print "Please create a start and end time for the selected animation.\n";


}

//---------------------------------------------------
// Create an Event Trigger
// This functionality will be added as needed,
// for the time being it will just add an event marker to the current time.

global proc eventTrigger ()
{
string $selAnim[] = `textScrollList -q -si TSLanims`;
string $allAnims[] = `textScrollList -q -ai TSLanims`;
string $allNotes[] = `textScrollList -q -ai TSLnotes`;
float $currentTime = `currentTime -q`;

string $newEventTimeName = ("Event." + $currentTime);
int $newEventTime;

string $result = `confirmDialog
-title "Start Time"
-message "Create an event at the selected frame?"
-button "Ok" -button "Cancel"
-defaultButton "Ok"
-cancelButton "Cancel"
-dismissString "Cancel"`;

if ($result == "Ok")
{
$newEventTime = `currentTime -query`;

// Save the end time variable to the scene
string $eventVariableName = $selAnim[0] + "." + $newEventTimeName;
fileInfo $eventVariableName $newEventTime;
if (size($allNotes) >! 2)
{
//if there is an end note, change it.
$allNotes[size ($allNotes)] = $allNotes[size ($allNotes)-1];
$allNotes[size ($allNotes)-2] = $newEventTimeName;

//clear TSLnotes for repopulation
textScrollList -e -ra TSLnotes;

//repopulate TSLnotes
for ($eachNote in $allNotes)
{
print ("Note: " + $eachNote + "\n" );
textScrollList -e -append $eachNote TSLnotes;
}
textScrollList -e -si $newEventTimeName TSLnotes;
}
else
{
print "Please create a start and end time first.\n";
}
}
saveEventNames();
}

global proc saveEventNames()
{
string $allEvents[] = `textScrollList -q -ai TSLnotes`;
string $selectedAnim[] = `textScrollList -q -si TSLanims`;
int $i = 0;
for ( $i; $i < size( $allEvents ); $i++ )
{
$allEvents[$i] = $selectedAnim[0] + "." + $allEvents[$i];
}
string $allEventsString = stringArrayToString( $allEvents, "|" );
string $varName = $selectedAnim[0] + ".Events";
fileInfo $varName $allEventsString;
}

//------------------------------------------------
// This is setup to export generic .anim files at the moment.

global proc export()
{
string $folderToSaveTo = `fileDialog -m 1`;
string $fileName = `file
-typ "animExport"
-pr
-es ($folderToSaveTo)`;
print ($fileName + "\n");
}

//-------------------------------------------------
//This will delete the selected anim.
global proc deleteAnim ()
{
string $savedAnimList[] = `fileInfo -q SavedAnimations`;
string $savedAnims[] = stringToStringArray( $savedAnimList[0], "|");
string $selectedAnim[] = `textScrollList -q -si TSLanims`;
string $allAnims[] = `textScrollList -q -ai TSLanims`;
int $i = 0;
for ( $i; $i < size( $savedAnims ); $i++ )
{
if ($savedAnims[$i] == $selectedAnim[0])
{
string $currentAnim[] = stringToStringArray( $savedAnims[$i], "");
string $newAnimList[] = stringArrayRemove($currentAnim, $savedAnims);
$savedAnims = $newAnimList;
string $newSaveAnimList = stringArrayToString ($savedAnims, "|");
fileInfo SavedAnimations $newSaveAnimList;
textScrollList -e -ri $selectedAnim[0] TSLanims;
textScrollList -e -ra TSLnotes;
textScrollList -e -si $allAnims[0] TSLanims;
AnimSelected;
}
}
}

1 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home