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.
Related Topics:
Defining and Enabling Macroscripts
Accessing Editable Polygon Data
NATURAL LANGUAGE
Package the code as macroScript to be able to use as a button, menu item or shortcut.
Enable only if a single object with an Editable Poly base object is selected.
When executed, get the base object of the selected object.
Go though all polygons of the base object and ask about their edges.
Count the edges and if they are not exactly 4, remember the index of the polygon.
Select all the non-quad polygons.
Go to Polygon Sub-Object Level in the Modify Tab.
MAXSCRIPT
macroscript SelectNonQuadPolys category: "HowTo" ( on isEnabled return ( selection.count == 1 and classOf selection[1].baseobject == Editable_Poly ) on execute do ( local face_selection = #{} local base_obj = $.baseobject local num_faces = polyop.getNumFaces base_obj for f = 1 to num_faces do ( local num_face_verts = polyop.getFaceDeg base_obj f if num_face_verts != 4 do face_selection[f] = true )--end f loop polyop.setFaceSelection base_obj face_selection max modify mode modPanel.setCurrentObject base_obj subobjectlevel = 4 )--end on execute )--end script
Macroscript SelectNonQuadPolys category:"HowTo"
(
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.
on isEnabled return
(
selection.count == 1 and classOf selection[1].baseobject == Editable_Poly
)
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.
on execute do (
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
local face_selection = #{}
We will need a user variable to store the polygons to be selected. We initialize the variable to an empty BitArray
local base_obj = $.baseobject
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!
local num_faces = polyop.getNumFaces base_obj
We will need the number of faces in the object in order to iterate through them.
for f = 1 to num_faces do
(
We will loop through all polygons in the base object – f will contain the index of the current polygon to be checked.
local num_face_verts = polyop.getFaceDeg base_obj f
Next we get a the number of vertices in the current polygon.
if num_face_verts != 4 do face_selection[f] = true
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.
)--end f loop
polyop.setFaceSelection base_obj face_selection
After checking all polygons, we can simply select all collected polygons.
max modify mode
In order to show the results of the selection to the user, we will first switch the command panel to modify mode...
modPanel.setCurrentObject base_obj
...then set the current object in Stack View to the base object we checked...
subobjectlevel = 4
...and finally switch to Polygon sub-object level to show the selected polygons.
)--end on execute
)--end script
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.
Back to