Undo - Some thoughts and a workaround

This is long but it is very worth it for those of you who are experiencing undo problems.

I have a theory on what is the main cause of the Undo bug, let me explain it and let you guys test this and see if my theory is true. If it is then the IntelliCAD developers are one step closer to actually fixing the undo problem. Some people have stated that they have had no problems with undo after they set their "undoctl" variable to 1, I think I know why this is and I believe I know why others still experience the problem. First let me explain the undoctl variable.

The undoctl variable controls how IntelliCAD, and AutoCAD interact with the use of the Undo command under various situations. The undoctl variable has the following settings: (lifted from the AutoCAD help files)

0 UNDO is turned off
1 UNDO is turned on
2 Only one command can be undone
4 Turns on the Auto option
8 A group is currently active (AutoCAD only)

Now some may ask how did we get the setting 5 as a default? Good question. The undoctl variable stores what is called a bit-code. This is a special kind of variable that can have more than the 5 settings listed above it can have a multiple of the settings above at once. Lets take 5 for example (the system default for both AutoCAD and IntelliCAD) 5 is a combination of 1 "UNDO is turned on" and 4 "Auto option is on". The value five is derived from taking both values and adding them together. Notice that the list does not go from 1-5 consecutively. The list is a set of numbers that when added together will never mean anything else than what the user intended it to mean, and what we can understand it to mean. It is simple math. 6 would be option 2 and option 4, and likewise 3 would be option 1 and option 2. Make sense?

Now let me explain why 5 is the default. The option 1 is obvious but option 4 may not be so obvious. The Undo Auto option is for menu commands. With this setting on IntelliCAD should automatically insert an Undo Begin and an Undo End before and after the macros programmed into your toolbars and screen menus. These marks are set so that if that particular menu item runs more than one command and you decide to undo that menu item it will undo all of the commands issued by that menu item at once. Otherwise with this setting off your macros will only undo one command at a time. Quite honestly I do not think that there are very many toolbar or pull down menu items that issue more than one command so setting undoctl to 1 may not be that big of a deal for most.

Here is my theory. I believe that the undo problem lies in the Undo Begin and Undo End options, and Undo Auto is a trigger for this Undo problem, because it inserts the Undo BE and END options automatically. This would make sense if the undoctl is turned off and the problem is gone for most. Now I also believe that lisp routines that are written with an undo BE and an undo END are also a cause of this problem and that is why it doesn't fix everyone's problems.

I have actually confirmed this. Try the following.

Draw some lines and circles
Now type Undo and enter BE for Begin
Draw some more lines and copy some lines
Now try to undo

You will notice that only commands previous to the undo begin command are undone.

This would explain why those who use lisp programs are still having the problem with undo. Lisp programmers use undo begin and end to make undoing of their commands easier. A program that draws a door for example may have an arc command and a couple line commands and maybe even a trim command to automatically draw a door for you. If the Undo BE and Undo END are not included in the lisp then you would have to undo each command at a time. The problem lies in the fact that not all commands are not allowed to finish. Often they are cancelled in the middle of the command, which would leave the Undo command hanging and would produce results we saw in the above example. Seasoned lisp programmers use error routines to "catch" a command that has been canceled and "clean up" which should include an Undo End.

Some steps you can take to workaround this until this is fixed:

1) Set your undoctl to 1 by adding the line (setvar "undoctl" 1) to the icad.lsp file

2) Do not run custom lisp routines unless you know that it is not using the Undo BE and Undo End commands. If you are brave you can open those lisp routines with notepad and look for a line near the beginning that reads (command "undo" "be") and add a ; (semi-colon to the front of that line This line will then be ignored. Do the same to the line near the end that reads (command "undo" "end"). Make sure you back up these files before editing them I would hate for you to loose some of these tools because of a mistake.

3) Lisp programmers: Make sure you use error correction routines to "catch" errors and exit a lisp routine "cleanly". Make sure the undo End is included in this. If you need help creating an error routine let me know I have one I can post. It is really quite simple to implement. Also test your routines to make sure that if the user hits cancel in the midst of your command that they will not encounter undo problems.

4) I could also write a small routine that redefines the UNDO command to disable the Begin and End commands. Then your lisp routines would think they have set these marks when in fact they have not. This may be a temporary fix that could eliminate all of the above steps, except for step 3 of course. Step 3 should every lisp programmers responsibility regardless of the state of Undo.

If these steps do not help then our Undo problems go much deeper, but this is at least one reproducible Undo problem that can be fixed.

David Trotz

I have had some undo problems, in which an unpredictably long series of commands have undone, once undoing everyting I had typed since opening the file. I assume this is related, and will try setting the undoctl variable to 1. Have you heard of this before, and do you suppose this may help with the problem? I have reverted to using my old version of ICAD 98 until this one was figured out. Thanks.


I've tried what David has explained and experienced the same problem. In addition, I go on a little more and find out why the Undo problem occurs every time I use Icad2000.
Our CAD system has been defined by a guy when we were using Acad R10. Since that time only necessary revisions are made to the acad.lsp file and since Icad98 worked very well on our sytem, we had only renamed the file to icad.lsp.
But when Icad2000 showed up, everything have changed. When we try to use Icad 2000 on our system and settings, Undo problem occurs evety time.
With the David's description, I have found the problem. In our icad.lsp file we have many descriptions like (defun c:ze()(command "zoom" "e")(princ)). These were very useful when using Acad R10 and also everyone is used to it very much that we still use these shortcuts instead of toolbar icons.
However now using and cancelling the "ze" command makes an error of Undo as described in David's posts.
What do you offer? Update all lisp files as described by David, or wait for Icad programmers to update the source code and use the new release?

David, thank you for your excellent approach to the problem.