A way to find out if there are more than one shape on a Transform / Mesh

855 views
Skip to first unread message

WKeel

unread,
Jun 10, 2015, 8:47:13 PM6/10/15
to python_in...@googlegroups.com
Hey guys, I am more a programmer so my understanding Maya is limited.

So I am making a Validator for my scenes and I need to clean up the Geo, right now I am noticing that there are mesh's that have duplicated shapes that rename themselves to 'polySurfaceShape6432' and this is conflicting seeing how there can be 5+ shapes that share the name 'polySurfaceShape6432'. Is there a way in Python I can tell how many shapes are on a node? I don't want to iterate through each object in the scene and compare it to another object to see if it has the same name. 

Any help would be appreciated, thanks! 
Cheers, 

mjlefevre

unread,
Jun 11, 2015, 6:06:00 AM6/11/15
to python_in...@googlegroups.com
Hey,

This method does iterate through shapes in the scene, but it doesn't seem to have too much overhead.

import string


shapes
= cmds.ls(shapes=True) # List shapes in scene
nonUniqueShapes
= [n for n in shapes if '|' in n] # Find all non-unique shape nodes
nonUniqueShapes
.sort(key=lambda x : x.count('|'), reverse=True) # Reverse list (children first)
for shape in nonUniqueShapes: # Rename
 cmds
.rename(shape, '{0}#'.format(shape.rpartition('|')[-1].rstrip(string.digits)))

wesley keeling

unread,
Jun 11, 2015, 1:51:06 PM6/11/15
to python_in...@googlegroups.com
That is so great MJ! Thanks so much it works, quick question to follow up, am I also able to delete a shape if there are two on an object? 
Message has been deleted

mjlefevre

unread,
Jun 12, 2015, 4:44:56 AM6/12/15
to python_in...@googlegroups.com
* deleted my original reply because it had syntax errors..is there any way to edit posts? :)

Hey, 

This might work. But are all the shapes duplicates? If not you would need to discern which shape you want to keep and which to delete.

import maya.cmds as cmds

transforms
= cmds.ls(transforms=True) # List transforms in the scene
for transform in transforms:
    shapes
= cmds.listRelatives(transform, shapes=True, noIntermediate=True) # Find the shapes from each transform (intermediate nodes not included)
   
if shapes is not None and len(shapes) > 1: # If the transform has multiple shapes..
        cmds
.delete(shapes[1:]) # Delete all but the first shape

Justin Israel

unread,
Jun 12, 2015, 7:19:38 AM6/12/15
to python_in...@googlegroups.com


On Fri, 12 Jun 2015 8:44 PM mjlefevre <matthew....@gmail.com> wrote:

* deleted my original reply because it had syntax errors..is there any way to edit posts? :)

moderators can edit posts.. but seeing as it is a mailing list... people have already received it in mail form :-)


Hey, 

This might work. But are all the shapes duplicates? If not you would need to discern which shape you want to keep and which to delete.

import maya.cmds as cmds

transforms = cmds.ls(transforms=True) # List transforms in the scene
for transform in transforms:
    shapes = cmds.listRelatives(transform, shapes=True, noIntermediate=True) # Find the shapes from each transform (intermediate nodes not included)
    if shapes is not None and len(shapes) > 1: # If the transform has multiple shapes..
        cmds.delete(shapes[1:]) # Delete all but the first shape

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/99b8363b-1798-4a58-b151-f0cfae0e625d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Marcus Ottosson

unread,
Jun 12, 2015, 7:38:21 AM6/12/15
to python_in...@googlegroups.com
I sometimes wish I could edit an email I've sent. Maybe in the future? =)​

wesley keeling

unread,
Jun 12, 2015, 1:45:14 PM6/12/15
to python_in...@googlegroups.com
MJ You are amazing!!! Thanks so much! Now I just have to figure out how to reference the exact mesh because 
More than one object matches name: [u'polySurfaceShape####'] #

On Fri, Jun 12, 2015 at 4:38 AM, Marcus Ottosson <konstr...@gmail.com> wrote:
I sometimes wish I could edit an email I've sent. Maybe in the future? =)​

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/G0_ug0QEjug/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODr-KEW%2BDdk1g2-3fdUfh_y%3D_%3DdDXG2sjO9nLzTpmxpBQ%40mail.gmail.com.

wesley keeling

unread,
Jun 12, 2015, 3:53:11 PM6/12/15
to python_in...@googlegroups.com
Figured it out shapes = mc.listRelatives(transform, shapes=True, f=True)
I had to get the full path, Thanks so muych guys!~ 

Reply all
Reply to author
Forward
0 new messages