Basically I have a loop inside a command that make some change on objects, and make some checks, if this check is OK the command stop, but if the check is not OK then undo all and check again with some different variables, ans make this until the check is OK or the time out.
I could delete all and start again, but I need the original Guu don’t change, if create a new one the Gui change.
Most commands that support Undo while the command is running maintain an internal structure of changes or additions. The Polyline is an example of this. When the command is done, all of the changes are dumped into the document.