Maya Python: Query for invalid mesh, get `maya.cmds.polyCheck` output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I had some scenes with an invalid mesh - that when exported using Alembic and reimported the mesh would have lost its UVs.
An easy way to produce such a mesh is with this little code snippet. It's the `mergeVertices=False` (which is also the default for that argument) that makes this break:
import maya.cmds as cmds
# Create hexagon and position it
hexagon = cmds.polyCylinder(r=1, h=4, sx=5, sy=1, sz=1)[0]
# Select sharp edges with angle above 80 degrees
cmds.select(hexagon + ".e[*]") # Select all edges first
cmds.polySelectConstraint(mode=3, type=0x8000, angle=True, anglebound=(80, 180))
# Bevel the selected edges
cmds.polyBevel(fraction=0.2, segments=3, offsetAsFraction=True, mergeVertices=False)
# Clear selection constraints
cmds.polySelectConstraint(disable=True)
# Clear history to avoid conflicts
cmds.delete(hexagon, ch=True)
Export and reimport the mesh - and voila, no UVs at all. You do get this nice little warning though:
// Warning: |pCylinder2|pCylinderShape1 normal vector scope does not match size of data, skipping normals
// Warning: UV set sample size is: 230 expecting: 42 or 170
Now what I want to do - is actually detect this issue before exporting on the meshes in the scene. I've found out that `maya.cmds.polyCheck` actually captures it.
Select the mesh and run:
from maya import cmds
result = cmds.polyCheck()
print(result)
# Result: 30
It prints the amount of errors detected. The Maya Output Window however is more informative - it states:
... DUPLICATE EDGE REFERENCE (0) IN SAME FACE : face 45, offset 172, local offset 2
... DUPLICATE EDGE REFERENCE (4) IN SAME FACE : face 45, offset 173, local offset 3
... DUPLICATE EDGE REFERENCE (7) IN SAME FACE : face 45, offset 175, local offset 5
... DUPLICATE EDGE REFERENCE (2) IN SAME FACE : face 46, offset 178, local offset 2
... DUPLICATE EDGE REFERENCE (6) IN SAME FACE : face 46, offset 179, local offset 3
... DUPLICATE EDGE REFERENCE (9) IN SAME FACE : face 46, offset 181, local offset 5
... DUPLICATE EDGE REFERENCE (18) IN SAME FACE : face 47, offset 184, local offset 2
... DUPLICATE EDGE REFERENCE (21) IN SAME FACE : face 47, offset 185, local offset 3
... DUPLICATE EDGE REFERENCE (23) IN SAME FACE : face 47, offset 187, local offset 5
... DUPLICATE EDGE REFERENCE (25) IN SAME FACE : face 48, offset 190, local offset 2
... DUPLICATE EDGE REFERENCE (28) IN SAME FACE : face 48, offset 191, local offset 3
... DUPLICATE EDGE REFERENCE (30) IN SAME FACE : face 48, offset 193, local offset 5
... DUPLICATE EDGE REFERENCE (16) IN SAME FACE : face 49, offset 196, local offset 2
... DUPLICATE EDGE REFERENCE (14) IN SAME FACE : face 49, offset 197, local offset 3
... DUPLICATE EDGE REFERENCE (11) IN SAME FACE : face 49, offset 199, local offset 5
... DUPLICATE EDGE REFERENCE (35) IN SAME FACE : face 50, offset 202, local offset 2
... DUPLICATE EDGE REFERENCE (39) IN SAME FACE : face 50, offset 203, local offset 3
... DUPLICATE EDGE REFERENCE (42) IN SAME FACE : face 50, offset 205, local offset 5
... DUPLICATE EDGE REFERENCE (51) IN SAME FACE : face 51, offset 208, local offset 2
... DUPLICATE EDGE REFERENCE (49) IN SAME FACE : face 51, offset 209, local offset 3
... DUPLICATE EDGE REFERENCE (46) IN SAME FACE : face 51, offset 211, local offset 5
... DUPLICATE EDGE REFERENCE (58) IN SAME FACE : face 52, offset 214, local offset 2
... DUPLICATE EDGE REFERENCE (56) IN SAME FACE : face 52, offset 215, local offset 3
... DUPLICATE EDGE REFERENCE (53) IN SAME FACE : face 52, offset 217, local offset 5
... DUPLICATE EDGE REFERENCE (65) IN SAME FACE : face 53, offset 220, local offset 2
... DUPLICATE EDGE REFERENCE (63) IN SAME FACE : face 53, offset 221, local offset 3
... DUPLICATE EDGE REFERENCE (60) IN SAME FACE : face 53, offset 223, local offset 5
... DUPLICATE EDGE REFERENCE (37) IN SAME FACE : face 54, offset 226, local offset 2
... DUPLICATE EDGE REFERENCE (41) IN SAME FACE : face 54, offset 227, local offset 3
... DUPLICATE EDGE REFERENCE (44) IN SAME FACE : face 54, offset 229, local offset 5
FOUND 30 ERRORS in poly object 000001603759E590
Now - what I really want is to be able to access the "invalid data" like what faces/edges are invalid, and why, from Python so I could report it to the user myself - and expose maybe a "select invalid" option for it too.
However, I can't seem to find any way to actually query the reported errors in a meaningful way and access the data.
What are my options to detect this issue, and maybe other issues too?