How to check group or mesh ?

How to check group or mesh ?

chalantorn_sup
Observer Observer
1,623 Views
2 Replies
Message 1 of 3

How to check group or mesh ?

chalantorn_sup
Observer
Observer

I've already listed all relatives, but I want to specify their types. For example, if it's grpSeaHawk, it's a group, but if it's various meshes like Body, Tank1, Tank2, ..., LHSideDoorB, it's a mesh. However, I'm not sure how to go about separating these types.

 

chalantorn_sup_0-1713957455806.png

 

0 Likes
Accepted solutions (1)
1,624 Views
2 Replies
Replies (2)
Message 2 of 3

FirespriteNate
Advocate
Advocate
Accepted solution

in Maya, "geometry" objects (i.e. meshes, curves, locators, etc..) are a shape node, with a transform parent. A "group" node is simply the transform node with no shape child.

There are a couple of different approaches to what you want, depending on use cases, but in general, when you use listRelatives, don't just rely on listing children, use the shapes flag/argument instead to list explicit shapes.

If the given transform has shapes, it's geometry (you can also specify the type to further refine/filter your results) and if it has no shapes then it must be an empty transform ("group"). For example, something like:

 

from maya import cmds

transformObjs = cmds.ls(transforms=True)
for item in transformObjs:
    # does it have any shapes?
    shapes = cmds.listRelatives(item, shapes=True)
    if not shapes:
        print(item, 'looks like a GROUP')

 

 

However, all that is only necessary if you are interested in distinguishing between transforms that are "groups" and those that are not. If you are only worried about getting specific types of geometery object (meshes for example), you can simply filter your ls command(s) to specific types, like so:

 

meshShapes = cmds.ls(type='mesh')
# this gives us the shape nodes, get their parent transforms:
meshObjects = cmds.listRelatives(meshShapes, p=True)
print(meshObjects)

 

 

Message 3 of 3

chalantorn_sup
Observer
Observer

Oh... Thank you, I stuck for this 1-2 hours.

0 Likes