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:
I can really use this - thanks.
ReplyDeletethis script is pretty amazing, thanks!
ReplyDeletevery nice, thanks to you for the help! :)
ReplyDeleteawesome script xD
ReplyDeleteScript is good, you can still make it better(as said by Bruce Lee ;)) by removing the namespaces(which are empty now, ideally) from your scene as renaming will not remove the namespaces from the scene file.
ReplyDelete// for loop is needed as your node may have multiple(nested) namespaces
for($ns in $buffer) {
// catch is needed, as for some reason it may not able to remove namespace,
// eg. if any node still having the namespace, which you are trying to remove
catch(`namespace -rm $ns`);
}
Note:- you can go clean in above loop, by removing the last element from the $buffer list as that is the node name.
Regards
Day Dreamer
www.daydreamer3d.weebly.com
thanks lot for all of the tutorials love you man :D
ReplyDelete