0

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?

Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125

1 Answers1

3

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())
)
Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
Swordslayer
  • 2,061
  • 1
  • 13
  • 15
  • Get primitive cube. Change it to an Editable mesh. Add, say a morpher modifier, (make sure no triangles are selected in face mode if you've run the script before) Then run the script. This time the selection will be everything (the inverse of which is no faces selected) so the script will appear not to have changed the cube - as opposed to leaving the top two faces on their own. I don't know if I have to specifically call the selection modifier (not sure how to do that) and add the inverted selection to that. – Ghoul Fool May 16 '13 at 08:37
  • Yes, because you are trying to set the selection on $, which is the result of the stack. The code I supplied doesn't do that, it sets the selection directly on the Mesh Select modifier. – Swordslayer May 16 '13 at 13:48