Problems renaming objects with the same names..

1,335 views
Skip to first unread message

Seth Lippman

unread,
Nov 24, 2008, 4:29:40 PM11/24/08
to python_inside_maya
Hello,
I am trying to do what should be a simple rename, but I am having a
few problems that I think are a bug, but hopefully just me not
realizing an error I am making.

I am writing a script to add a suffix to all meshes : "_geo". It goes
like this:

import maya.cmds as mc
meshs = mc.ls(l=True,type='mesh')
for mesh in meshs:
# get parent transform
transforms = mc.listRelatives(mesh, fullPath=True,parent=True)
transform = transforms[0]
print 'working on ' + transform
# if there is no _geo at the end, put one there
if not transform .endswith("_geo"):
shortName = transform.split("|")
newName = shortName[-1] + "_geo"
print "rename %s to %s " % (transform,newName)
mc.rename(transform,newName)

If I create a new scene, with 2 sphere meshes, it works fine.
If I group each sphere into its own group, and then name the spheres
the same, I get errors.

group1|pSphere
group2|pSsphere

When I run the script I do get

group1|pSphere_geo
group2|pSphere_geo

but I also get this error in the script editor:
working on |group1|pSphere1
rename |group1|pSphere1 to pSphere1_geo
working on |group2|pSphere1
rename |group2|pSphere1 to pSphere1_geo
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: More than one object matches name: pSphere1_geoShape //
// Error: Cannot convert data of type int[] to type int. //
// Error: More than one object matches name: pSphere1_geoShape //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Illegal operation "!" on data of type int[]. //
// Error: Illegal operation "!" on data of type int[]. //
// Error: Illegal operation "!" on data of type int[]. //
// Error: Illegal operation "!" on data of type int[]. //
// Error: Cannot convert data of type int[] to type int. //
// Error: Cannot use data of type int[] in a scalar operation. //


Anyone have any idea why? And what other method I could do to rename
the same named objects?

Richard Kazuo

unread,
Nov 24, 2008, 5:06:43 PM11/24/08
to python_in...@googlegroups.com
Weird. Running your script with grouped pSpheres1 I get no errors and they rename accordingly.
Maybe you got some expression, scriptJob or something running on the background?
Tested in Maya 8.5 by the way...

Richard

Seth Lippman

unread,
Nov 24, 2008, 6:22:33 PM11/24/08
to python_in...@googlegroups.com
I had another friend test it too.. Looks like its local to my machine
config. Will fire up a vanilla maya session and double check. Thanks.

Seth Lippman

unread,
Nov 24, 2008, 6:40:27 PM11/24/08
to python_in...@googlegroups.com
Yep, false alarm. Deleting all prefs and envs this code works fine...
I'll will find the offending code / scriptJob and post it if its
anything interesting.

But, it the spirit of discussing Python in Maya, is this the most
efficent way to be renaming things? Is there a better way?

It seems simple enough as it is now..

Ofer Koren

unread,
Dec 1, 2008, 4:21:00 PM12/1/08
to python_in...@googlegroups.com
Give pymel a shot:

import pymel as pm
for mesh in pm.ls(type='mesh'):
    p = mesh.getParent()
    if p and not p.endswith("_geooo"):
        print 'renaming %s' % p
        p.rename("%s_geooo" % p.name())

It's not doing things much differently from your version really, just a bit more concise, allowing you to avoid all the long-name/short-name issues that come up in maya scripting.

Seth Lippman

unread,
Dec 5, 2008, 8:46:46 PM12/5/08
to python_in...@googlegroups.com
Nice, I will.
Reply all
Reply to author
Forward
0 new messages