Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Maya Python: Query for invalid mesh, get `maya.cmds.polyCheck` output

Maya Python: Query for invalid mesh, get `maya.cmds.polyCheck` output

BigRoy
Advocate Advocate
477 Views
3 Replies
Message 1 of 4

Maya Python: Query for invalid mesh, get `maya.cmds.polyCheck` output

BigRoy
Advocate
Advocate

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?

0 Likes
478 Views
3 Replies
Replies (3)
Message 2 of 4

cheng_xi_li
Autodesk Support
Autodesk Support

Hi BigRoy,

 

I think you can try scriptEditorInfo command to save these outputs into a file and check the file later.

 

If that wasn't working, you could try cmdFileOutput command instead. 

 

Hope it helps.

 

Yours,

Li

0 Likes
Message 3 of 4

BigRoy
Advocate
Advocate

Thanks, @cheng_xi_li 

 

Unfortunately both commands do not provide me with the intended result.

 

For example, capturing `polyCheck` in a  `cmdFileOutput` does not capture the output window text from the poly check command. It does capture regular Script Editor output, like a `print` statement.

 

from maya import cmds

cmds.cmdFileOutput(o="E:/test.txt")
cmds.polyCheck()  # with the invalid mesh selected
print("TEST")
cmds.cmdFileOutput(close=True)

 The same goses for the `scriptEditorInfo` command:

from maya import cmds

cmds.scriptEditorInfo(historyFilename='E:/test.txt', writeHistory=True)
cmds.polyCheck()
print("TEST")
cmds.scriptEditorInfo(writeHistory=False)

None of the output window text is redirected nor written to the file.

0 Likes
Message 4 of 4

cheng_xi_li
Autodesk Support
Autodesk Support

Hi Roy,

 

In that case, you can try to add -log parameter when launching Maya. It'll write the outputs in the output window to a file 

 

e.g.,

maya -log d:\log.txt

Then you can monitor it with your own Python scripts.

 

Hope it helps.

 

Yours,

Li

0 Likes