View Full Version : Search for Objects with same name

12 December 2012, 09:18 AM
Hey there, I have got a problem with a huge file including tons of geometry.
Sadly some of the geometry has the same name, which causes problems while referencing and overriding.
So I would like to have a script which lists me all objects with same name.
Perhaps even automatically renames them ^.^?!
I am not really experienced with MEL and could not find anything on the internet, so I would really appreciate a little help.
Or is there a already tool ? Find naming Issues or something like that ^.^

Best greets from snowy Germany! :)

12 December 2012, 10:51 AM
Try this to find name clashing.
I wrote it long time ago but I think it works.

def NameClashDetect():
clashingNames = []
mayaResolvedName = []
allDagNodes = = 1)
for node in allDagNodes:
if len(node.split("|")) > 1:
print "Name clash found: " + node
print "UI name: " + clashingNames[-1]
return mayaResolvedName

To solve name clashing is a bit harder. I don't have a one click solution right now, but you can use this script to get the list of clashing nodes. Then you can select those and use some kind of rename tools available on the net.

12 December 2012, 10:23 AM
Hey Zeedorf!

Thanks a lot for the fast reply, sadly it is not working.
I get the error

// Error: def NameClashDetect[]:
// Error: Syntax error //

I am working with Maya 2012, any ideas how to get it working? That would be sooooo great! :)

12 December 2012, 11:53 AM
Probably you run python script in MEL window.
But it gives error in Python win also...

12 December 2012, 02:12 PM
Yeah indeed, I tried MEL first, then Python - but as you said - same error :(

12 December 2012, 07:14 PM
your error states the function uses square brackets '[]' instead of parentheses '()'. I'm assuming you wrote it out rather than copy&paste?
Try checking the characters in the code, or better yet copy and paste it.

Also for debugging I suggest turning on showing error line numbers in the script editor.

12 December 2012, 09:08 PM
My ninja rename script on creative crash has this function

here is the code below.

string $all[] = `ls -tr -sn -fl`; string $obj;

string $duplicateArray[] = {};

for($obj in $all)


if(`gmatch $obj "*\|*"`)


stringArrayInsertAtIndex(0, $duplicateArray , $obj);



select $duplicateArray;

string $Selection[] = `ls -sl -fl -type "transform"`;

select $Selection;

showHidden -a;

12 December 2012, 09:13 PM
to check if a short name is unique, i use the "ls" command, like so:

def isNameUnique(name):
shortName = name.split("|")
longNames =[-1], l=True)
longNames ="*"+shortName[-1]), l=True)

if len(longNames) > 1:
return 0
return 1

to rename something with a new, unique name be mindful of namespaces. Looking back on this code, i should've relied more on python's string methods instead of regex, but it still works fine, just harder to understand.

def makeNameUnique(name):
m = re.compile("[^|]*$").search(name)
shortname =

m1 = re.compile("^.*:").match(shortname)
if m1:
namespace =
namespace = ""

m2 = re.compile(".*[^0-9]").match(shortname)
if m2:
stripSuffix =
stripSuffix = shortname

if namespace:
namespace = re.compile(":$").sub("", namespace)
cmds.namespace(set=(":" + namespace))

newname = cmds.rename(name, (stripSuffix + "#"))
return newname

12 December 2012, 08:33 AM
Hey there so many answers! Thx a lot! :)

@ldunham1: I copy and pasted it - also gets an error - but without the []

@bk3d: Wahuhuuuhu! Thx a lot! The script works just great and I just downloaded the whole Ninja Rename Toole! Thank you so much! :)

@rgkovach123: Some how it is just not working, but perhaps I am using Python wrong? I am using it like Mel - but in the Python Tab (copy paste and strg+enter), on execution nothing happens, not even errors... O.o
(never used python befor)

Buts thanks everyone for helping!! :)

12 December 2012, 03:01 PM
i didn't include the modules required to run those code snippets.

you need to add to the top of the python tab:

import maya.cmds as cmds
import re

CGTalk Moderation
12 December 2012, 03:01 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.