Undo - Some thoughts and a workaround

#1
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

#3
You can save your drawings as any version when using SaveAs and select the filetype.

On the other hand you can program an automatic save in another file version. If you have an ICAD version with VBA on board there is a Sub:

Sub SaveAs(SaveFile As String, [Version As FileVersions = vicVersionR14])
Member of IntelliCAD.Document

the options vicVersion??? will allow you to save in all versions that can be selected manually. ie for version 10 use vicVersionR10 in the macro.

I don't think Lisp has this capability.

Regards
John Finlay

#5
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.

#6
If you follow my suggestions above for all releases of IntelliCAD 2000, your undo problems should be minimal if not gone. BricsNET IntelliCAD however will not work this way, they have rewritten the undo command (since 2.2.0016), and introduced some new bugs. According to the developers there the new undo is much easier to debug and should be stable fairly quickly. Regardless I think this undo bug is getting ridiculous since Undo is so vital to getting work done in IntelliCAD. It is one thing when it doesn’t undo anything at all, and it is quite another when undo undoes arbitrary commands. This should have been fixed a year ago.
There is one amendment to my above instructions however. There is no need to use undo begin and undo end commands in lisp routines for IntelliCAD since IntelliCAD implements this automatically. For portability between the AutoCAD and IntelliCAD do a simple check to see if AutoCAD is running the lisp and if so call the undo begin and undo end commands appropriately, else don’t issue the commands.
I hope this is helpful.


------------------
David Trotz

#7
David,

Your explanation looks great and makes alot of sense. AutoCAD does indeed have a few system variables that can use the sum of numbers assigned to achieve multiple settings. I will be sure and pass this on to our programmer. I personally have had no problem but then the only lisp files I generally load are my own and none of them contain the Begin and End commands.

I agree that the Undo bug should have been fixed by now as this has been one of the major bugs since the beginning. I believe your explaination will definetly help as I think you may have discovered the problem.

Fantastic work and you are to be commended.

Thank you very much.

Melodie

#8
Hello,

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.