View Full Version : renaming every nTH object

10 October 2005, 07:22 AM
I need to mass rename every object selected to a different name every nth occurence. For example I have 12 objects and four names, so for objects 1-4 are renamed to the 4 names assigned then 5-9 are given the same names but with a numbered post-fix.

So for every 4 objects the 4 objects are renamed, this continues until we finish at the list of selected objects.

I hope this made sense.

10 October 2005, 12:16 PM
Something like this might get you started...

global proc renameit(string $newNames[])
int $numNewNames = `size $newNames`;

string $sel[] = `ls -sl`;
int $numSel = `size $sel`, $i;

for ($i=0; $i<$numSel; $i++)
int $index = $i % $numNewNames;
rename $sel[$i] $newNames[$index];

If you call "rename" and give it a name that already exists it will append a number at the end to make it unique so if that is all you want in terms of a numbered post-fix then that's all you would have to do.

CGTalk Moderation
10 October 2005, 12:16 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.