Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Maya® / MEL / Selecting and Renaming Multiple Objects?
  RSS 2.0 ATOM  

Selecting and Renaming Multiple Objects?
Rate this thread
 
12471
 
Permlink of this thread  
avatar
  • Total Posts: 3
  • Joined: 22 May 2007 12:10 PM


I have a list of multiple objects all with nearly the same name e.g. tire01, tire02, tire03, etc. and I need to put in a MEL script that will select all objects “01-10” and then rename them to something different with “01-10” at the end.  For instance if I wanted to rename tire0# to cylinder0# what script would I type for that?



Replies: 0
avatar

in mel it would be something like this with tokenize, but you have to pay attention to the tokenize separater(which is why “_” is seen alot):

{
select 
--allDagObjects;
string $nodes[] = `ls -sl`;
for(
$node in $nodes)
{
         string $buffer[]
;
    
$n = `tokenize $node "0" $buffer`;
    if(
$n 1)
    
{
        rename $node 
"tire#";
    
}
}
}

in python you would use string slicing to separate the name from number, or use reg expressions and other methods:
changes pSphere1-9 to puddleDucks#

def pyRename(oldName='pSphere',newName='puddleDucks',numericSuffix=1):
    
maya.cmds.select(allDagObjects=True,r=True)
    
sel maya.cmds.ls(sl=True)
    for 
i in range(0,len(sel),1):
        
sel[i]
        t 
s[:(-1*numericSuffix)]
        
if(== oldName):
            
maya.cmds.renamesnewName)


Replies: 0
avatar

Hi, I know Paul has already done a fine job of answering this, but I just though I would jump in with another method.

// --------------------------------------------------------------------- **
// FILE:    FG_simpleRename.mel
// DESC:    Select specified objects and rename
// DATE:    27th May 2008
// VERS:    Fuzzygoat - Maya_2008
// --------------------------------------------------------------------- **

global proc FG_simpleRename(string $oldNamestring $newName{
    
    string    $objAll[]
;
    
string    $padder;
    
string    $paddedName;
    
int          $objCount 1;
    
    
$allObj = `ls -transforms ($oldName + "*")`;
    
    for(
$objEach in $allObj{
    
        
if($objCount<10$padder "_000";
        else if(
$objCount<100$padder "_00";
        else 
$padder "_0";

        
$paddedName $newName $padder string($objCount);
        
rename $objEach $paddedName;
        
$objCount++;
    
}
}

// --------------------------------------------------------------------- **
// END
// --------------------------------------------------------------------- **

To execute this you will need to type ...

source FG_simpleRename.mel;
FG_simpleRename("tire","cylinder");

Which will rename as follows ...

tire01 -> cylinder_0001
tire02 -> cylinder_0002
tire03 -> cylinder_0003
...
...

garyc



Replies: 0
avatar
  • RodGreen
  • Posted: 09 August 2008 03:49 PM

I wrote up some tutorials on this topic exactly.  The problem comes with dealing with hierarchies and shapes etc.

Check it out:

http://www.rodgreen.com



Replies: 0
avatar
  • mBakr
  • Posted: 22 January 2011 04:54 PM

This is an old thread, but one that still shows up in web searches.

The script-free way to rename multiple objects is to use the input box in the toolbar. From the Maya docs:

Rename
Edit the name of the currently selected object. When more than one object is selected, Maya increments a number at the end of the name for each object.



Replies: 0
avatar
  • dushyantk
  • Posted: 14 February 2011 08:50 PM

Sure this is thread pops-up a lot in web searches.

So people might find this script useful:

Comprehensive Renamer: Maya Rename Script

[url=http://www.creativecrash.com/downloads/28666]Click Here to Download (CreativeCrash)
[/url]
One more rename script for Maya, written in mel, I’am trying to make it as feature rich as possible, so all requests are welcome.

Copyright (C) 2011 Dushyant Kumar Kashyap//
MEL script for MAYA 8.0+//
File: comprehensiveRenamer.mel
Desc: This is a simple mel script that allows the user to rename multiple Objects.
With lots-n-lots of options.//
Author: Dushyant Kumar Kashyap ()

[url=http://programmerslimbo.blogspot.com]http://programmerslimbo.blogspot.com
[/url]
Usages:  Just Source Script, it will call the required procedure automatically.



Dushyant Kumar Kashyap.
http://programmerslimbo.blogspot.com/

Replies: 0