This uses the tokenize command. For more info, check out this mel tutorial on how to use the tokenize command. Essentially it's looping through every node in your scene, checking if there are colons in the name of it, and renaming the object to what it would be with no namespaces.
// Get All Nodes In Scene
string $allNodes[] = `ls` ;
// Loop Through Them
for($node in $allNodes) {
// Tokenize And Rename
string $buffer[] ;
tokenize $node ":" $buffer ;
string $newName = $buffer[size($buffer)-1] ;
catch(`rename $node $newName`) ;
}
The reason I call this dirty is because it has potential to cause naming conflicts in your scene file. In a lot of cases namespaces are there for a reason, so you should make sure it's safe to remove them before doing so. Maya does not support having more than one object with the same name, so if you run this script it may end up changing the names of some of your nodes. Usually this is in the form of adding a number to the end of it. (i.e. hand_CTRL becomes hand_CTRL1). Be sure to save your scene before running this (as you should with any MEL script) and do some testing before you continue forward to make sure everything is working like it should.
Also:
- Every Maya scene file has a list of namespaces that have at one time or another been used in that scene. This script will not remove any from that list.
- If something is referenced in your scene, this will not be able to remove the namespace properly.
- You'll see a slew of error messages pass by, this is Maya trying to rename nodes that aren't allowed to be renamed. You can ignore these.
For more reading about namespaces in Maya, check out the following: