Notifications
Clear all

[Closed] Undo delete objects

Hi everyone

I’m not sure if I’m missing something obvious, but when I’m having problems deleting objects and then undoing it.

The following test code creates some boxes, deletes them and then tries to undo the deletion. I’ve tried undoing via “max undo” as well as theHold.Begin() and theHold.Restore() but I still end up with no boxes in the scene.

fn undoTest =
(
    delete objects
    max undo
)

fn theHoldTest =
(
    theHold.Begin()
    delete objects
    if theHold.Holding() do
    (
        theHold.Restore()
        theHold.Cancel()
    )
)


for i=0 to 5 do box position:[i*2,0,0] height:1 width:1 length:1
format "object count after building boxes: %
" objects.count
--"object count after building boxes: 6"

with undo on
(
    undoTest()
    format "object count after delete then undo: %
" objects.count
    --"object count after delete then undo: 0"

    /*
    theHoldTest()
    format "object count after hold then restore: %
" objects.count
    --"object count after hold then restore: 0"
    */
)

Does anyone know what’s going on?

6 Replies

I did notice that if in the listener I evaluate

delete objects

and then evaluate

max undo

then it seems to work. I just can’t get it to work as part of a script :curious:

undo "myScript - Delete Objects" on 
		(
    delete objects
)

Thanks for the reply – I’m finding that on its own your code snippet works but if I’m doing that inside a function I end up with 6 invisible boxes in the scene

for i=0 to 5 do box position:[i*2,0,0] height:1 width:1 length:1

fn undoTest =
(
    undo "myScript - Delete Objects" on 
    (
        delete objects
    )
    max undo
    ok
)

undoTest()

Do you get the same result?

Works for me…

I noticed that deleting object by maxscript is risky in some keys. Some times max crash when I try to delete some object or max script indicate system exception and object can’t be deleted because of some reason in spite of I used it in “try – catch mode”, don’t know why. Also some times performing undo can crash max, I’m not sure why but I guess it’s up to many factors which is hard to predict. Right now I’m working on such a code and I got to tell you from my experience , try to avoid “delete with undo – combination” as much as you can. I was happy that all works on my test scenes but where comes to practice there are some scenes that make this combination max crash.

Works for me…

Ugh that’s not what I was hoping to hear I’ve tried it on several instances of 3dsmax now and they all produce invisible objects after deleting objects and undoing. Invisible as in – I can select them by clicking where they would be in the scene or the select by name dialog, they render fine as well – I just can’t see the polygons, vertices etc. Object properties are normal too…

…try to avoid “delete with undo – combination” as much as you can

The reason I’m investigating this in the first is actually quite interesting – I was finding that save selected (saveNodes) on a single object that’s part of a huge scene was really slow. However if I first deleted everything that isn’t selected and then do the saveNodes on the selection it is much faster (e.g. 7 seconds compared to 20 seconds). Deleting everything that isn’t selected first also ends up with a smaller max file.

Of course afterwards I need to bring back the deleted objects to restore my scene, so I’ve played around with the undo system and ran into these issues.

The only workarounds I’ve found so far (but I’ve yet to test what impact it has on timings) is to clone/instance the invisible objects and delete the originals. Creating a box, attaching the invisible objects and deleting the box sub-object works as well but I’d also have to match the pivot to the original object’s pivot. Oh – another workaround to fix my invisible objects is to reopen the file but of course that takes far too long for a big scene and I’m trying to speed up the saveNodes process