View Full Version : searchReplaceNames

08 August 2007, 05:46 PM
Hi all!
I'm very new to mel (2 days)

I have som renaming to do:

These are my file names:

etc.... I think there was 81

I need to remove the "_polySurface1" part
and then keep only the LThread_curve_tread_1 (and the following numbers)

but if I run the "searchReplaceNames "_polySurface1" "" "selected";"

it does just this...but it changes the last number to whatever number the
last file had, this wont do.
so now, instead of 1, 2 and 3 etc. I now have:


Ive been trying all kinds of things
tokenize and rename etc
to get it working, but it keeps, changing the numbers Arrggh.. :)

I need it to be numbered from 1 to 81, but without the "_polySurface1" part

Any help on this will be so very greatly appreciated!!

/daniel, the total MEL N00b

08 August 2007, 06:38 PM
Can't you just do something like:

int $i = 0;

for ($i = 0; $i < $numberOfItems; $i++) {
rename ( "LThread_curve_tread_" + $i + "_polySurface1") ("LThread_curve_tread_" + $i);

08 August 2007, 10:31 AM
Hi again and thanks alot for your qiuck reply!

I did some minor modifications, to your posted code...and tada!!

It seems as it is now working :)....I'm so happy

Thanks again!

Here it is the modified code:


string $objectsToRename[] = `ls -sl -dag`;
int $i;

for ($i = 1; $i <= size ($objectsToRename); $i++) {
rename -ignoreShape ( "LThread_curve_tread_" + $i + "_polySurface1") ("LThread_curve_tread_" + $i);



08 August 2007, 04:01 PM
I spooke to soon it worked on my test with only three objects :(
But when I run it on my 82 stupidly named objects it goes back to,
my old problem, renumbering what should be numberd 1-81 is now 82-162 ...buhu hu..

Why!!?? is it becouse of some automagic number padding or the lack of, that exist in
rename ?


daniel...starting to pour whiskey in a glass hysterically sobbing...

08 August 2007, 04:18 PM
I am not sure it's easy to say what's the problem without taking a look at the scene or an excerpt from it :)


08 August 2007, 05:56 PM
sure thing..

I'll see what I can do..

I could mail you a rar file?

Or try to download from here:

08 August 2007, 11:19 PM
There exists a name clash with LThread_curve_tread_1 set, you have bunch of other ones with similar name too. You can see that by trying to simply rename your thread object, it will be 82 and not 1 because that object already exists. So what Maya does is increment the counter until a "vacant" name is available and that happens only at index 82...

So you just have to clean up your scene a little bit :)

08 August 2007, 08:51 AM
thank you so much Henry! :thumbsup:

I'll see if I can come up with a scritpt to clean up my mess first and then run my renamer,

Any hint on how to approach this?
I'm not asking for completet solution just some hints, it makes for good practice :)

Well thanks again you've been much helpful.. since this is my third mel task ever on my third day(fourth with this new cleanup) and I'm totally hooked on mel and your fast replyes have been great, since the MEL td gods at work are on vactaion, I'm trying to learn on my own.


08 August 2007, 02:34 PM
Well it all depends on what you want to have in your scene in the end. I personally would delete everything except the polygon meshes, run the rename script. Then I'd write a script to create all those sets you had.

You could also do this: before renaming the object check if such object exists (`objExists`), if it does, rename or delete it, then perform the actual renaming for your mesh objects.

Hope it helps :)

CGTalk Moderation
08 August 2007, 02:34 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.