Skip to content

Instantly share code, notes, and snippets.

@dy-dx
Last active June 26, 2021 07:31
Show Gist options
  • Save dy-dx/505ba0c246c7a67a9b1e6fed1e46226e to your computer and use it in GitHub Desktop.
Save dy-dx/505ba0c246c7a67a9b1e6fed1e46226e to your computer and use it in GitHub Desktop.
Maya script that selects all visible non-quad faces in the scene.
{
// Make sure we're in object mode, otherwise some currently selected faces can mess this up.
// Need to switch on component mode first to make this work in all cases.
changeSelectMode -component;
changeSelectMode -object;
// Select all face components
select -r `listTransforms "-type mesh -visible"`;
PolySelectConvert 1;
// Filter the selection to only ngon faces.
// -sz 1 is for tris, 2 is for quads, 3 is for ngons
polySelectConstraint -t 8 -m 2 -sz 3;
$ngonFaces = `ls -sl`;
// Select all faces again, filter to triangles.
select -r `listTransforms "-type mesh -visible"`;
PolySelectConvert 1;
polySelectConstraint -t 8 -m 2 -sz 1;
// Turn off the selection constraint.
polySelectConstraint -m 0 -sz 0;
// Reselect triangles
select -add $ngonFaces;
// A hack to deselect other objects we don't care about
select -r `ls -sl`;
$nonQuadFaces = `ls -sl`;
// ls -sl -o gives us shape nodes but we want their parent transforms instead
$nonQuadShapes = `ls -sl -o`;
$nonQuadObjects = `listRelatives -p $nonQuadShapes`;
// Only hilite objects containing selected faces.
hilite -r $nonQuadObjects;
$msg = "No visible non-quad faces.";
if (size($nonQuadFaces) > 0) {
// Query number of selected faces.
$_countNonQuads = `polyEvaluate -faceComponent`;
$countNonQuads = $_countNonQuads[0];
// Switch to face component selection mode.
SelectTool;
changeSelectMode -component;
selectType -allComponents 0 -polymeshFace 1;
$msg = $countNonQuads + " non-quad faces selected.";
}
inViewMessage -smg $msg -fade -pos topCenter;
print($msg + "\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment