How To > Select Non-Quad Polygons |
MAXScript lets you access Editable Poly object data and explore relationships between polygons, vertices and edges. When using polygon modeling it is usually desirable that all polygons are kept as quads. The following script will select all polygons that have less or more than 4 edges.
Defining and Enabling Macroscripts
Accessing Editable Polygon Data
The macroScript will be called SelectNonQuadPolys . To use the script, you can use Customize... to drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or to assign to a keyboard shortcut.
The isEnabled handler should return true or false and determines the enabled state of the button / menu item. When true , the button will be available. When false , it will be grayed out. In the return expression, we check whether only one object is selected in the scene and whether its base object class is Editable Poly. The script will only work on objects that meet both conditions.
The on Execute handler will be executed each time the macroScript is executed (by pressing the button, selecting from the menu, pressing the shortcut etc.). The handler contains the "body" of the script.
Macroscript_Body_Event_Handlers
We will need a user variable to store the polygons to be selected. We initialize the variable to an empty BitArray
Our script will work on the base object only. This means that the object may have modifiers on top of the base object – they will not be taken into account as polygon modeling usually happens at the base level anyway. Because we already made sure in the isEnabled handler that there is only a single object selected, we can access the selection using $ without worrying that it might contain multiple objects!
We will need the number of faces in the object in order to iterate through them.
We will loop through all polygons in the base object – f will contain the index of the current polygon to be checked.
Next we get a the number of vertices in the current polygon.
If the number of vertices is not 4, we should select the polygon so we set the respective bit in the bitArray corresponding to the current face to true.
After checking all polygons, we can simply select all collected polygons.
In order to show the results of the selection to the user, we will first switch the command panel to modify mode...
...then set the current object in Stack View to the base object we checked...
...and finally switch to Polygon sub-object level to show the selected polygons.
To use the script, you can use Customize... to drag the script from the category "HowTo" to a toolbar, a menu, a quad menu or to assign to a keyboard shortcut. Select a single object with an Editable Poly base object and the script will be enabled. Execute and the non-quad polygons will become selected.