[Closed] EditablePoly.Remove() is too greedy?
I’m having this weird issue trying to remove edges from editable polys. If I call Remove() to delete selected edges from within a function then unselected isolated edges are removed as well. If I make the same remove() call from the listener, the isolated edges are retained.
I’ve put together a demo app that shows the problem. I’ve only tested in Max2009. I think I’m missing something simple, like a refresh, or an update, or a ‘rebuild the freaking internals’ that happens after the scripts complete, but I’m stumped and I just want to get past this.
fn BuildTester = (
-- Set up an editable poly object with 2 material ids
tester = convertToPoly(box widthsegs:3 heightsegs:3 lengthsegs:3)
select tester
max Modify Mode
polyop.setfaceMatId tester #{1..(polyop.getnumfaces tester)} 1
polyop.setfaceMatId tester #{14,41,50} 2
newmat = multimaterial numsubs:2
newmat[1].diffusecolor = red
newmat[2].diffusecolor = green
tester.material = newmat
tester
)
fn RemoveInternalEdges epoly =
(
select epoly
max Modify Mode
epbase = epoly.baseobject
eCount = polyOp.getNumEdges epbase
polyop_setEdgeFlags = polyop.setEdgeFlags
polyop_getFaceMatID = polyOp.getFaceMatID
boundary = bit.set 0 21 true
polyop_setEdgeFlags epbase #{1..eCount} 0 mask:boundary
for i = 1 to eCount do
(
theFaces = (polyOp.getFacesUsingEdge epbase #(i)) as array
if theFaces.count == 2 do
(
if polyop_getFaceMatID epbase theFaces[1] != polyop_getFaceMatID epbase theFaces[2] then
(
polyop_setEdgeFlags epbase #{i} boundary
)
else
(
norm1 = polyOp.getFaceNormal epbase theFaces[1]
norm2 = polyOp.getFaceNormal epbase theFaces[2]
crossLen = (length (cross norm1 norm2))
if (crossLen) > 0.0001 do
(
polyop_setEdgeFlags epbase #{i} boundary
)
)
)
)
boundaryEdges = polyop.getEdgesByFlag epbase boundary
subObjectLevel = 2
polyOp.setEdgeSelection epbase (-boundaryEdges)
-- Calling remove() here, inside the function, results in isolated edges
-- getting removed as well as the selected edges, and the green faces are gone!
-- epoly.Remove() -- Uncomment to see the problem
epoly
)
-- Run the test
delete objects
resultObj = RemoveInternalEdges (BuildTester())
/*
-- Calling remove() directly from the listener , immediately
-- after the call to RemoveInternalEdges gives the expected result
resultObj.Remove() -- select and press ctrl-enter to execute
*/
Hey Mike,
I think I have seen this problem. If you are holding down Ctrl when Remove is called, Max will remove the isolated vertices. It’s probably hard coded the way the corresponding button in the Editable Poly rollout works. So holding Ctrl removes the isolated vertices, else it just removes the edges.
Light
I think that’s what it is. If you run the script by clicking “Execute All” from the “Tools” menu instead of the Ctrl-E shortcut, it works as expected. So as long as this is part of a tool that doesn’t require the control key to be held down to launch, you don’t have anything to worry about.
That’s really annoying though. I’ve requested many times to have an explicit MaxScript command that emulates the Ctrl-Backspace behavior with no luck. But instead, we have the Ctrl key actually affecting how the .Remove() command works.
that. is. so. annoying.
i’m about to bust out my hex editor and ‘fix’ max.
stomp NOPs all over that test, if i can find it.
edit: ctrl-a then numpad-enter works correctly too. I got in the habit of ctrl-enter while developing on my laptop.
if (keyboard.controlPressed) do
(
MessageBox "Release the Control Key!"
)
epoly.Remove()
grrrrr.
remove edges by flag… not by selection.
another thing is to block any key input before the function execution.