Monday, November 29, 2010

Detect N-gons in Maya using MEL

I learned something really interesting today and I just had to share it.

I'm not much of an organic modeler, but sometimes I have to get my hands dirty. Someone asked something that I've been wondering for a while. Is there a way to select ngons, or polygons with more than 5 or more sides. Someone else responded with the following MEL script:

polySelectConstraint -mode 3 -type 0x0008 -size 3;
polySelectConstraint -disable;

After selecting your mesh, run this. All of your 5+ sided faces will be selected. Now you can do with them what you will...

If you're new to MEL like I am, this can look like a string of nonsense, but it's really pretty simple. Let's take a second and dissect this:

polySelectConstraint - "By using the polySelectConstraint command you can select connected components, components within a shell, or components on open borders." -source

-mode 3 - Mode 3 is "all and next", in other words it selects everything meeting the requirement of the constraint. But what is the requirement of the constraint? That's defined next.

-type 0x0008 - type 0x0008 is face. So the type of your selection will be a face, not an edge or vertex.

-size 3 - size 3 is nsided. (fyi, 0 is off, 1 is triangles and 2 is quads)

So the first line of this simple script is plainly read as "Create a polySelectConstraint for every face that is nsided". The second line is read, "disable the constraint". Once you have your selection, there's no need to keep it enabled.

Pretty useful, huh?


No comments:

Post a Comment