Thursday, February 9, 2012

Handy Script To Check Extension in Mel Scripting

I wrote this short script to help me with getting user interface stuff.
I imagine it can come in handy for animation transfer according to naming conventions of controls, or just the ideas about working with strings.



/////return 1 if argument has second argument string extension
/*
needs arguments

string file name
string extension to check ex: ".mel"
*/
global proc int
isExtension(string $fileName, string $extension)
{
int $result = 0;
////tokenize all dots
string $buffer[]; //store tokens for every object
string $lastToken = "";

tokenize $fileName "." $buffer;

/////take the last token
$lastDotToken = $buffer[ ( size($buffer)-1 ) ];

//match it with extesion
if( strcmp($lastDotToken,$extension) == 0 ){ $result = 1; }
return $result;
}



Please also check out the amazing work by Tim Taylor and Andrea Mailo (their online articles on Star Wars III were sensational, I learned about writing from Maya to mel from reading their work. Also check out the amazing online blog of Jakub Krompoic (syntetik dot blogspot dot com).