Shot gun rename

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 03 March 2009   #1
Shot gun rename

How do you rename a group of objects in an array with an incremental number at the end?

For example if you have a selection of spheres and you would want to name them:
sphere02 etc....

This is what I have so far. I just can't get it to increment the number.

string $sel[] = `ls -sl`;

int $i;
for ($i = 0; $i < size($sel); $i++)

	rename Sphere;
Old 03 March 2009   #2
it gets a bit more complicated than this if you want a '0' in front if the number is less than 9 but that should work, also you don't need to declare the '$i' if you're using a counter-type loop

string $sel[] = `ls -sl`;
 for ($i = 0; $i < size($sel); $i++)
 	rename $sel[i] ("Sphere" + i);
Old 03 March 2009   #3

 import maya.cmds as mc

selected =

for sel in selected:
	mc.rename(sel, 'newName' + '#')

Ok, But Can You Do It...ON FIRE!
Old 03 March 2009   #4
Thanks guys.

Last edited by nottoshabi : 03 March 2009 at 01:12 AM.
Old 03 March 2009   #5
How do I make the name to be a variable?

string $sel[] = `ls -sl`;
string $sel2[] = `ls -sl`;

 for ($i = 0; $i < size($sel); $i++)
	 rename $sel[$i] ("$sel2" + $i);

It only names the first one. It never adds the number and I get a warning.
// Warning: Removing invalid characters from name. //

In my $sel2[] I have an object named Blahh. In my $sel[] I have 5 objects it only names the first object Blahh. And the rest are left alone.

Old 03 March 2009   #6
don't put quotes around $sel2. You also need to specify which item in sel2 you want.

Also note that unless you run the first two lines separately $sel[] and $sel2[] would be the same objects.

string $sel[] = `ls -sl`;
string $sel2[] = `ls -sl`;

for ($i = 0; $i < size($sel); $i++)
rename $sel[$i] ($sel2[$i] + $i);
Old 03 March 2009   #7
$sel and $sel2 are going to be to different variables fed in from other proc's. Just this part of the code got me stuck. Now I'm getting an error and it only names the first obj.
// Error: New name has no legal characters. //
Old 03 March 2009   #8
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 07:41 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.