06 April, 2009

A trick to increment a string in Maya

I was developing a script to increment version & save the current file where the script checks for version tag (*_v1.ma) and then increments it. I took a long path first where I extract the version tag then extract the number and increment it. And ofcourse Maya will give you a warning when it converts string to integer. So to solve that working I was wondering what to do and it clicked to me that maya can increment it for me. And it's simple!

You need to have the sub string where the numerical part is at the end
e.g. modlObj_artist_v1

Here is the sctipt.

string $curName = "modlObj_artist_v1";
// we will create nodes under this node so that we know they are unique
string $parent = `createNode transform`;
createNode -name $curName -parent $parent transform;
// create it again so maya renames it with incremental suffix
$newName = `createNode -name $curName -parent $parent transform`;
// delete
delete $parent;
print $newName;

Though in my case I still need to extract version tag in order to check if its present.

1 comment:

  1. hehe actually not a bad idea. Thanks for blogging. A lot of nice tidbits in here.

    ReplyDelete