CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 03-21-2009, 04:15 AM   #1
nottoshabi
Lord of the posts
 
nottoshabi's Avatar
portfolio
Shaby
Character TD
Los Angeles, USA
 
Join Date: Feb 2002
Posts: 874
Send a message via MSN to nottoshabi
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:
sphere01
sphere02 etc....

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

Code:
string $sel[] = `ls -sl`; int $i; for ($i = 0; $i < size($sel); $i++) { rename Sphere; }
 
Old 03-21-2009, 05:28 AM   #2
greatPumpkin
Frequenter
Adrian Tsang
Character TD
London, United Kingdom
 
Join Date: Feb 2008
Posts: 181
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

Code:
string $sel[] = `ls -sl`; for ($i = 0; $i < size($sel); $i++) { rename $sel[i] ("Sphere" + i); }
 
Old 03-21-2009, 09:44 AM   #3
Pyrokinesis
Frequenter
portfolio
Shaun Friedberg
Technical Director
Weta Digital
Wellington, NZ
 
Join Date: May 2006
Posts: 268
Code:
import maya.cmds as mc selected = mc.ls(sl=True) for sel in selected: mc.rename(sel, 'newName' + '#')
__________________
Ok, But Can You Do It...ON FIRE!
 
Old 03-23-2009, 10:51 PM   #4
nottoshabi
Lord of the posts
 
nottoshabi's Avatar
portfolio
Shaby
Character TD
Los Angeles, USA
 
Join Date: Feb 2002
Posts: 874
Send a message via MSN to nottoshabi
Thanks guys.

Last edited by nottoshabi : 03-24-2009 at 01:12 AM.
 
Old 03-25-2009, 07:51 PM   #5
nottoshabi
Lord of the posts
 
nottoshabi's Avatar
portfolio
Shaby
Character TD
Los Angeles, USA
 
Join Date: Feb 2002
Posts: 874
Send a message via MSN to nottoshabi
How do I make the name to be a variable?

Code:
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.

Why?
 
Old 03-25-2009, 08:02 PM   #6
greatPumpkin
Frequenter
Adrian Tsang
Character TD
London, United Kingdom
 
Join Date: Feb 2008
Posts: 181
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-25-2009, 08:51 PM   #7
nottoshabi
Lord of the posts
 
nottoshabi's Avatar
portfolio
Shaby
Character TD
Los Angeles, USA
 
Join Date: Feb 2002
Posts: 874
Send a message via MSN to nottoshabi
$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-25-2009, 08:51 PM   #8
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 08:17 PM.


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