[MAYA] Finding Transforms with Invalid Mesh Data

I came across an instance where the deleteEmptyGroups function from cleanUpScene.mel wasn’t deleting empty transforms. Somehow the transform had bad mesh data attached to it that wasn’t showing up in the viewport.

I tried looking around for a function that finds invalid mesh data, but ended up going the hacky route of callign cmds.polyEvaluate('transform_path', area=True) which returned a string for transforms with invalid mesh data.

Is there a better way to do this that I missed? This way seems hacky and unoptimal.

For reference, here’s the code:

all_mesh = cmds.ls(type='mesh')
mesh_transforms = cmds.listRelatives(all_mesh, parent=True, path=True)
for mesh_tr in mesh_transforms:
    # When area evaluation is called on transform
    # of an invalid mesh, it returns a string
    res = cmds.polyEvaluate(mesh_tr, area=True)
    # Skip results that aren't strings
    if not isinstance(res, str):
        continue
    cmds.delete(mesh)

My gut-reaction guess is that you’ve got an intermediate mesh under that transform. cmds.getAttr(meshNode + ".intermediateObject") will return True if that’s the case

But (of course) I can’t look at your file to see if that’s the case :slight_smile: So if that’s NOT the answer, I’d save just that single object out to a .ma file and search through it for the name of the shape node. Then I’d look for any attrs on the shape node that I didn’t recognize or looked out of place. Maybe that’ll give you a better method of finding these invalid meshes.

Thanks for the reply, I don’t think I can provide the maya file.

Doing some testing, it doesn’t seem to be an intermediate mesh. From how I understand, these transforms with bad mesh data is coming from the artists merging or moving meshes to another transform while they work.

That sounds like a prime cause of leftover intermediate meshes. Let’s try one more time…

Try running this in your file:

for mesh in cmds.ls(type='mesh'):
    cmds.setAttr(mesh + '.intermediateObject', False)

Any intermediate meshes will show up as bright green in your viewport.
It may also be worth turning on “Display → Shapes” in the Outliner for this, and searching through the hierarchy for extra shape nodes.

1 Like

Oh! Okay, I see where I went wrong when testing out your suggestion. I was running the attribute test on the transforms and not the mesh nodes themselves. This does seem to be the issue with the transforms, I didn’t know this could be a thing in Maya, thanks so much for explicating further.