-- v2.0 macroScript waRp_Ngons category:"waRp Tools" buttonText:"waRp Ngons" tooltip:"Select all objects that have Ngons" ( on IsEnabled return ( selection.count >=1 ) on Execute do ( with redraw off ( -- disable command panel flickering WM_SETREDRAW=0xB local cmdPan_hwnd = if (windows.getChildHWND #max "Command Panel") == undefined then windows.getChildHWND 0 "Command Panel" else windows.getChildHWND #max "Command Panel" -- windows.sendmessage cmdPan_hwnd[1] WM_SETREDRAW 0 0 max modify mode showEndResult = false -- predefine this polyop commands. Increase the speed. local getFaceCount = getNumFaces local poGetFaceDeg = polyop.getFaceDeg local poSetFaceMatID = polyop.setFaceMatID -- undo on ( -- create the material only once. If it is in for loop the speed of the script will decrease local PolyMtl = standard diffuse:(color 35 35 35) SpecularLevel: 60 Glossiness: 30 name:"PolyMtl" local multimat = multimaterial numsubs:2 name:"NgonMtl" multimat.materialList = #( PolyMtl , (standard diffuse:(color 215 197 0) name:"YellowMtl")) filteredScMtls = for i in scenematerials where refs.dependentNodes i firstOnly:on != undefined collect i -- filter scenematerials, because it updates itself in a fixed intervals for i in filteredScMtls do ( if i.name == multimat.name then multimat = i else if i.name == "PolyMtl" do PolyMtl = i ) local ngonObjs = #() local selObjs = selection as array selObjs.material = PolyMtl for obj in selObjs do ( local TsFlag = false if classof (obj.modifiers[1]) == TurboSmooth then ( obj.modifiers[1].enabled = false TSflag = true ) epMods = for m in obj.modifiers where classof m == Edit_poly collect m if epMods.count != 0 then ( modpanel.setCurrentObject epMods[1] -- local num_faces = getFaceCount obj local ngonFaces = #{} for f = 1 to num_faces where ((obj.Edit_Poly.getFaceDegree f node:obj) != 4) do ( append ngonFaces f ) -- if ngonFaces.numberset >= 1 then ( subobjectlevel = 4 max select all -- or use the next line -- obj.Edit_Poly.Select #Face #{1..num_faces} obj.Edit_Poly.SetOperation #SetMaterial obj.Edit_Poly.materialIDToSet = 0 -- clear the selection max select none -- or you can use the next line -- obj.Edit_Poly.SetSelection #Face #{} obj.Edit_Poly.Select #Face ngonFaces obj.Edit_Poly.SetOperation #SetMaterial obj.Edit_Poly.materialIDToSet = 1 obj.Edit_Poly.Commit () subobjectlevel = 0 -- append ngonObjs obj ) ) else if classof obj.baseobject == Editable_Poly then ( modpanel.setcurrentobject obj.baseobject local num_faces = getFaceCount obj local ngonFaces = #{} for f = 1 to num_faces where ((poGetFaceDeg obj f) != 4) do ( append ngonFaces f ) -- ngonFaces is a bitarray. To get the count of the faces in it you have to use .numberset, not .count. -- open the maxscript help file, search for BITARRAY and then read about the what the COUNT return. if ngonFaces.numberset >=1 then ( poSetFaceMatID obj #all 1 poSetFaceMatID obj ngonFaces 2 append ngonObjs obj ) ) if TSflag == true then ( obj.modifiers[1].enabled = true ) ) if ngonObjs.count >=1 then ( select ngonObjs ngonObjs.material = multimat IsolateSelection.EnterIsolateSelectionMode() ) ) windows.sendmessage cmdPan_hwnd[1] WM_SETREDRAW 1 0 -- rferesh command panel max create mode ) ) )