The script is used to change the naming in Figure 1 to Figure 2, renaming objects in Maya with the same name to different names.
The renamed rule is: Group Name _ Original name _ ordinal
Check out the Official Handbook for Maya: http://download.autodesk.com/global/docs/maya2012/zh_cn/index.html
You can see how commands are used in the Script Editor in the following ways:
Help LS;
Edit the Mel script with the script editor that comes with Maya, and paste the script code:
1 string$ls _names[] = ' ls-tr ';//get the object name collection under outline view2 string$current _name;3 for($current _nameinch$ls _names) {4 //Print ("Name:" + $current _name+ "\ n");5 string$buffer [];6 int$numTokens = tokenize ($current _name,"|", $buffer);//Use | To display its full path when the same name is present7 if(Size ($buffer) >1) {8 //print ("Need to rename it...\n");9 string$tmp _name;Ten string$new _name =""; One for($tmp _nameinch$buffer) { A //print ("Tmp_name:" + $tmp _name+ "\ n"); -$new _name = $new _name + $tmp _name +"_";//Plus Group name - } the$new _name + ="#";//add an auto-accumulate number to it - //print ("New name:" + $new _name+ "\ n"); -Print"Old Name:"+ $current _name+"---->new Name:"+ $new _name+"\ n"); -Rename ($current _name, $new _name);// Renaming + Clear ($buffer); - } +}
View Code
Use the following methods:
1. Select all the code in the Mel's edit window
2. Click menu "File" in Script Editor and "Save script to Tool shelf"
3. Prompt to enter a new name
4. After confirmation, you will see a script named after the name on the current tool shelf.
Note:
Reprint must indicate the source and the author name
Blue Flash
Maya Script--Renaming the name of an object