I don’t remember well but I was thinking there was a direct way to get every transform nodes having a shape in them.
For now I use:
import maya.cmds as mc
for node in mc.ls(exactType='transform') :
if not mc.listRelatives(node, shapes=True) : # skip the node if there is no shape above it
continue
# deal with your transform with shapes here...
But I’m almost sure Maya provide a nice way to have such nodes in one line instead of a check.
I’m not sure what that is supposed to do Theodox. The interior ls call returns all camera shapes and all transforms, then the exterior just restricts that to transforms, which has the same result as just calling ls with the -tr flag (unless I’m mistaken).
The only thing to keep in mind with rgkovach123’s method, is that if a transform has multiple shapes under it, you will get duplicate listings of that transform. Use a set to remove duplicates. You also don’t need to use a list comprehension and can pass the result of cmds.ls straight to cmds.listRelatives
[QUOTE=capper;25643]I’m not sure what that is supposed to do Theodox. The interior ls call returns all camera shapes and all transforms, then the exterior just restricts that to transforms, which has the same result as just calling ls with the -tr flag (unless I’m mistaken).
The only thing to keep in mind with rgkovach123’s method, is that if a transform has multiple shapes under it, you will get duplicate listings of that transform. Use a set to remove duplicates. You also don’t need to use a list comprehension and can pass the result of cmds.ls straight to cmds.listRelatives
Doh, I was testing with camera. But the outer ls removes the shapes from the results of the inner, which I thought was what OP wanted. -tr includes both shapes and transforms
Maybe I’m missing something but cmds.ls(type=‘mesh’, tr=True) returns all transforms in the scene in addition to mesh shapes. It doesn’t restrict the result to mesh transforms.
I just read rgkovachs as having transforms and shapes mixed and thought ‘oh, just filter it to transforms!’ listRelatives > ls mesh is the the way to do it.