PDA

View Full Version : Search for Objects with same name


Pinycho
12-10-2012, 08: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! :)

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


def NameClashDetect():
clashingNames = []
mayaResolvedName = []
allDagNodes = cmds.ls(dag = 1)
for node in allDagNodes:
if len(node.split("|")) > 1:
mayaResolvedName.append(node)
clashingNames.append(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.

Pinycho
12-11-2012, 09: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! :)

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

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

ldunham1
12-12-2012, 06: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.

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

http://www.creativecrash.com/maya/downloads/scripts-plugins/data-management/c/ninja-rename

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;

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



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

if len(longNames) > 1:
return 0
else:
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 = m.group(0)

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

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

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

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

Pinycho
12-14-2012, 07: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!! :)

rgkovach123
12-14-2012, 02: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-14-2012, 02: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.