|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| Selecting and Renaming Multiple Objects?
|
|
|
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?
|
|
|
|
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 -r -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):
s = sel[i]
t = s[:(-1*numericSuffix)]
if(t == oldName):
maya.cmds.rename( s, newName)
|
|
|
|
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 $oldName, string $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
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
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/
|
|
|
|
|
|