From creating a cube the following code should select the top two triangles, invert that selection and then delete those newly selected faces. So far so good. However, I seem to run into trouble when there’s a modifier (or more) on the base cube.
(
--clear the listener
clearListener()
theObj = $
-- init. an array to collect faces
selArray = #{}
invArray = #{}
append selArray 3
append selArray 4
-- get the number of faces in the object
theMeshCount = theObj.numfaces
-- invert the array
for f = 1 to theMeshCount do
(
if (selArray[f] == false) then invArray[f] = true
else invArray[f] = false
)
-- set the face selection in the EMesh
setFaceSelection theObj invArray
-- go to modify mode
max modify mode
-- select the mesh
select theObj
-- add the Mesh Select modifier
modPanel.addModToSelection (Mesh_Select ())
-- go to Face level
subObjectLevel = 3
--add a delete mesh, preserving the selection
modPanel.addModToSelection (deleteMesh())
)
So where am I going wrong?
What kind of trouble do you run into, specifically? I've just tried it and if there are no topology-changing modifiers it seems to work as expected. It might be better to get the obj.mesh face count instead so that it would work with primitive objects as well, or maybe you intended to add the modifiers to the bottom of the stack - in that case uncomment the /../ chunks in the code below to make it work on baseobject instead.
Also, inverting the bitarray is as simple as setting its length and putting a minus sign in front of it.
(
local theObj = selection[1]
local theMesh = theObj.mesh
local theMod = Mesh_Select()
local selArray = #{3..4}
selArray.count = theMesh./*baseObject.*/numFaces
delete theMesh
addModifier theObj theMod /*before:theObj.modifiers.count*/
setFaceSelection theObj theMod (-selArray)
max modify mode
/*modPanel.setCurrentObject theMod*/
subObjectLevel = 3
modPanel.addModToSelection (DeleteMesh())
)