|
Tutorials at Lizard Lounge Graphics : Maya - illegal character script
I've recently been doing a lot of MEL scripting as part of my work at the Weta Workshop developing tools to use for production of Jane and the Dragon. One of the things I've needed is a way to let users name files from a custom GUI that I'm building and avoid any characters that might conflict with Maya's naming conventions along with the Windows file name restrictions. What follows is a handy little proc that you are welcome to use in your projects to help with conforming naming issues to fit your needs.
What it does is accept a string from the procedure call and tests to see if any characters that are out of bounds are present. If the string contains no illegal characters then it returns an int of 1, otherwise it returns a value of 0. This has been tested and works fine under Maya v6.0.
Read the fine print before you use this.
global proc int charCheck(string $word)
{
string $tmp;
int $badChar = 0;
int $stringSize = `size ($word)`;
for ($i = 1; $i < ($stringSize + 1); $i++)
{
$tmp = `substring $word $i $i`;
if (`gmatch $tmp "[!0-9A-Za-z_-]"` == 1) // Modify this line if needed.
{
print ("\n" + $tmp);
$badChar = 1;
warning "Illegal charcacters!";
break;
}
}
if ($badChar == 0)
{
return 1;
}
else
return 0;
}
//----------------------------------------------------------------------------------
// End charCheck
|