Notifications
Clear all

[Closed] Is there a way to save the undo buffer?

Currently we have a process that runs to check the scene for any errors created by the artist. Due to its lengthy process, or some method its calling, the undo buffer gets wiped after its completed. Is there anyway to save the undo buffer, and the restore it? even a hacky method would work. I looked in thehold, but i don’t have much experience with it.

4 Replies

Check which part of your “tool” deletes the UNDO buffer and fix it if it is possible.

just save the scene before you start the process, simples

 autosavedir = ((GetDir #scene) + "/AutoSave")
if not doesfileExist autosavedir then makeDir autosavedir;
lastsavedfile = ((GetDir #scene) + "/AutoSave/AutoSave_" + bit.intAsHex (genclassid returnValue:true)[random 1 2]) + ".max";
saveMaxFile lastsavedfile;

as an example

Hold the maxfile and then restore it.
Pretty much the same as save and load, but I think a bit faster.
But you shouldn’t be losing your undo stack unless it is calling GC() somewhere

It appears to be ‘getMAXFileObjectNames’ in 2019.3, when the count is around 1000. Using it seems to clear the undo buffer.

NOTE: Basically, get something in your undo buffer...like create a box, and move it. Then run the script below, change the file save path accordingly.

(
	saveFile  = "e:\\a.max"
	
	for i = 1 to 1000 do
	(
		box pos:[random 1 250, random 1 250,random 1 250]
	)

	savemaxfile saveFile
	
	print ("CURRENT UNDO COUNT : " + theHold.getCurrentUndoLevels() as string )	
	getMAXFileObjectNames (maxfilepath + maxfilename)	
	print ("END UNDO COUNT : " + theHold.getCurrentUndoLevels() as string )
	ok	
)

I get this.

“CURRENT UNDO COUNT : 3”
“END UNDO COUNT : 0”
OK