HeapSize and Edit_Poly undo issues


When trying to move verts on an Edit_Poly modifier I’ve noticed that if too verts are moved to different locations in a loop the undo stack gets cleared. For instance:

sp = Sphere segs:64 name:#test isSelected:on
ep = Edit_Poly()
addmodifier sp ep
max modify mode
modPanel.setCurrentObject ep

numv = ep.GetNumVertices()
seed 0
vrtsToMove = #()
oldPositions = #()
newPositions = #()
for k=1 to (numv/2) do (
    newVrt = 0
    while newVrt == 0 do (
        tmpNum = (random 1 numv)
        if (finditem vrtsToMove tmpNum == 0) do newVrt = tmpNum
    append vrtsToMove newVrt
    append oldPositions (ep.GetVertex newVrt)
for i=1 to vrtsToMove.count do (
    x=((random -1 1) + oldPositions[i].x)
    y=((random -1 1) + oldPositions[i].y)
    z=((random -1 1) + oldPositions[i].z)
    append newPositions [x,y,z]

subobjectlevel = 1

svp = ep.setVert
for i=1 to vrtsToMove.count do (svp #{vrtsToMove[i]} newPositions[i] node:$)

I figured this is memory related and so increased the heap size as a test, and it seemed to solve the problem…until I ran the script a few more times and it cleared the undo stack again. Does anyone know of a way around this issue?

(Edited for clarity with better example)


when you ask any question with code provided please also give a test scene (object) to play with.
for example the answer to your question depends on mesh you work with


specifically to your code…
setVert has an option to set multiple verts at once if you pass an array of destination positions. in this case it will be only one function call with one restore (undo) object.


but … if for any reason you need to do the geometry change operation many times under same block of undo (at least for Edit_Poly) you can do only first and last iteration with undo on and all other in-between with undo off

edit_poly mesh change stored as full set of all vert positions for every geometry change with no difference how many verts were really changed.