Author Topic: Woah, undo the drawing ...  (Read 3699 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Woah, undo the drawing ...
« on: April 27, 2010, 01:55:29 PM »
I have come across a situation that has me puzzled, and I would like your thoughts on the issue.
I was working on a drawing, had probably 35 minutes worth of work done, cranking away, and started a command I couldn't follow through with yet.  It was one of those,
(Thought process ...
Quote
... draw a line between these two objects, then mirror, then label.
I started the line command, then realized I was on the wrong layer for labeling the object.  As habit would follow, I reached up and hit the escape key.  My drawing went and 'undone' the last 35 minutes of my work.  Talk about desparation.  I went from desparation, into panic mode, and then anger in a really short period of time.   :realmad:

My initial thoughts are my LiSP routines.  Perhaps I forgot to end the undo recording commands.  But I've gone through them with a finetooth comb and can't find anything missing.  Perhaps my Error catching is not set properly, but I don't see anything out of place.  Then again, perhaps I am not understanding error catching as well as I thought I did.
Here's a copy of one of my error catching pieces of code:
Code: [Select]
(defun c:ConvertDGN (/ *error* origTstyl origDstyl origLstyl origexpl origLayr
                        origColr origASN origOS dwgType dwgblocks Entity
                        LTnotePath BlocksInCtab dwgPreF dwgDesc TodaysDate
                        Text Dims LTnote
                     )
  (vl-load-com)
  (defun *error* (msg /)
    (template:on-error msg)
    (princ)
  )
  (command ".undo" "be")
  (setq origTstyl (getvar "textstyle")
        origDstyl (getvar "dimstyle")
  ...
  ...
;; Reset System Variables
  (setq LTnotePath nil)
  (setvar "osmode" origOS)
  (setvar "autosnap" origASN)
  (setvar "filedia" 1)
  (setvar "cmdecho" 1)
  (command ".undo" "E")
  (ALERT "Conversion successful.")
  (princ)
); end function

;; Error control  Thanks to Kerry - theSwamp
(pragma '((unprotect-assign template:on-error)))
;;
(defun template:on-error (msg / tmp)
;;----- Cancel any Active Commands -----------------------------
  (while
    (< 0 (getvar "cmdactive"))
    (command)
  )
  (setvar "menuecho" 1)
  (command ".undo" "e" "undo" "")
;;----- Display error message if applicable _-------------------
  (cond ( (not msg))                                            ; no error, do nothing
        ( (member
            (strcase msg t)                                     ; invoke a cancel
             '("console break" "function cancelled" "quit / exit abort")
          )
        )
        ( (princ (strcat "\nApplication Error: "                ; else, an error message
                         (itoa (getvar "errno"))
                         " :- "
                         msg "\n"
                 )
          )
        )
  )
  ;;----- Reset System Variables ----------------
  (setvar "osmode" origOS)
  (setvar "autosnap" origASN)
  (setvar "textstyle" origTstyl)
  (setvar "celtype" origLstyl)
  (setvar "explmode" origexpl)
  (setvar "clayer" origLayr)
  (setvar "cecolor" origColr)
  (setvar "cmdecho" 1)
  (setvar "filedia" 1)
  (setvar "menuecho" 0)
  (command ".redraw")
  (setq *error* nil
        dwgtype nil
        LTnotePath nil
        LTnote nil
  )
  (princ)
)
;;
(pragma '((protect-assign template:on-error)))
;;

So my question I guess is this, have any of you run across this situation ??
I have found that even if I have just run simple autocad commands, not running any custom lisp routines, this dilemma can still happen.
Do you guys have anything in place to help prevent this from happening ??
I was thinking about putting something like this at the end of every routine I have just to try and safeguard it, but I don't know that it will help.
Code: [Select]
  (while
    (< 0 (getvar "cmdactive"))
    (command)
  )

I don't know what is causing this nor do I know how to control it properly.
Your thoughts will be greatly appreciated, even if you just want to ramble on and tell us your own story.  It may spark a thought or two on how to fix this potential disaster.   Thanks.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Woah, undo the drawing ...
« Reply #1 on: April 27, 2010, 02:08:31 PM »
This jumped out and slapped me in the face...
Code: [Select]
;;----- Cancel any Active Commands -----------------------------
  (while
    (< 0 (getvar "cmdactive"))
    (command)
  )
  (setvar "menuecho" 1)
  [color=red](command ".undo" "e" "undo" "")[/color]
You are defining the end of an Undo group, then undo'ing once.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Hangman

  • Swamp Rat
  • Posts: 566
Re: Woah, undo the drawing ...
« Reply #2 on: April 27, 2010, 02:29:40 PM »
This jumped out and slapped me in the face...
Code: [Select]
;;----- Cancel any Active Commands -----------------------------
  (while
    (< 0 (getvar "cmdactive"))
    (command)
  )
  (setvar "menuecho" 1)
  [color=red](command ".undo" "e" "undo" "")[/color]
You are defining the end of an Undo group, then undo'ing once.

Right.  When an error occurs, it is to stop the recording of the process, and undo what has currently been recorded, so the drawing is back to its original state before the lisp routine was initially run.
I am thinking this is a good practice, but ... well, what do you think ??  What do you do ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Woah, undo the drawing ...
« Reply #3 on: April 27, 2010, 02:33:32 PM »
This jumped out and slapped me in the face...
Code: [Select]
;;----- Cancel any Active Commands -----------------------------
  (while
    (< 0 (getvar "cmdactive"))
    (command)
  )
  (setvar "menuecho" 1)
  [color=red](command ".undo" "e" "undo" "")[/color]
You are defining the end of an Undo group, then undo'ing once.

Right.  When an error occurs, it is to stop the recording of the process, and undo what has currently been recorded, so the drawing is back to its original state before the lisp routine was initially run.
I am thinking this is a good practice, but ... well, what do you think ??  What do you do ??
Issue an ending Undo mark. I've seen situations where that method would be useful, but I think that's where you problem is. Check through your error handlers and undo marks - something is funky.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Hangman

  • Swamp Rat
  • Posts: 566
Re: Woah, undo the drawing ...
« Reply #4 on: April 27, 2010, 03:30:57 PM »
...
Issue an ending Undo mark. I've seen situations where that method would be useful, but I think that's where you problem is. Check through your error handlers and undo marks - something is funky.

Could you give me some idea's on what I might be looking for ??  Does the Undo command keep track of how many times it records or is it simply through the command structure ??  I understand AutoCAD keeps a list of commands in a history so you can use the undo command, but does UNDO keep the same type of history ??  I was to the understanding it didn't.  I understood it to just keep track of the points, when it started, when it stopped, ... that kind of thing.

As I posted above, that IS my error handler.  Should I have something more ?? and if so, what ??
I have this same format throughout all of my routines.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hangman

  • Swamp Rat
  • Posts: 566
Re: Woah, undo the drawing ...
« Reply #5 on: April 27, 2010, 03:43:30 PM »
Perhaps it's in the wrong place.
Code: [Select]
(setvar "menuecho" 1)
  (command ".undo" "e" "undo" "")
;;----- Display error message if applicable _-------------------
  (cond ( (not msg))                                            ; no error, do nothing
        ( (member
            (strcase msg t)                                     ; invoke a cancel
             '("console break" "function cancelled" "quit / exit abort")
          )
        )
        ( (princ (strcat "\nApplication Error: "                ; else, an error message
                         (itoa (getvar "errno"))
                         " :- "
                         msg "\n"
                 )
          )
        )
  )

The UNDO "End" is issued before the console break or hitting the escape key.
Perhaps I need to move it to just after the console break or escape key ??

The main problem I'm having with this, is it is a random occurance.  Sometimes it happens, sometimes it doesn't.  I haven't been able to recreate a scenario where I can get it to happen each time I invoke it.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Woah, undo the drawing ...
« Reply #6 on: April 27, 2010, 05:37:04 PM »
I always use vla-StartUndoMark and vla-EndUndoMark, I haven't had a problem with these - its not a solution to your problem, just my 2 pence  :-)

Hangman

  • Swamp Rat
  • Posts: 566
Re: Woah, undo the drawing ...
« Reply #7 on: April 27, 2010, 06:34:55 PM »
OK, a few questions regarding UNDO.
First, does anyone have any other info regarding 'groups' besides the help file and autodesk's white sheets (the basically just copied what the help file already sais).

Second, I haven't seen people post much in terms of UNDO, nor have I heard any comments regarding the use of it much.
How do you use UNDO in your lisp routines ??  If you have a rather large routine, don't you record the actions so the user doesn't have to 'undo' a few hundred times to go back to the beginning if they need to ??

Third, what is your UNDOCTL variable set at ??   I'm currently set at 53.  32 for layer operations, 16 for zoom & pan, 4 is auto turned on, 1 is undo turned on.   I'm wondering if the 'auto' could be grouping every command I run into a single undo.  But something is still causing an error function to go back to the beginning of somewhere when I hit the esc key.  Which brings me to my next question;

Four, do you use the UNDO / Mark option a lot ??  Do you use it at all ??  According to the help file, the Mark is ignored when an Undo 'BEgin' recording is taking place, which means you can't put a mark in the middle of a routine if you are recording the actions of the routine.  If there is an Undo recording taking place unbeknownst to the user, placing marks every so often will not help at all, which puts me back in my same situation without a temporary fix until I can find the problem.

Thanks guys for your input and thoughts.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Woah, undo the drawing ...
« Reply #8 on: April 27, 2010, 06:38:51 PM »
I would replace: (command ".undo" "e" "undo" "")
           with: (command ".undo" "e")

However, I still say you need to look through each routine and find out where an undo mark (begin, etc.) is being placed without being closed out with an end.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Woah, undo the drawing ...
« Reply #9 on: April 27, 2010, 06:47:23 PM »
Perhaps take a look at the code posted by David Bethel at the end of this thread, he uses the UNDO command regularly  :-)

Serge J. Gianolla

  • Guest
Re: Woah, undo the drawing ...
« Reply #10 on: April 27, 2010, 09:28:18 PM »
I don't know what is causing this nor do I know how to control it properly.
Your thoughts will be greatly appreciated, even if you just want to ramble on and tell us your own story.  It may spark a thought or two on how to fix this potential disaster.   Thanks.

Regardless of fixing the routine, shouldn't Autosave have kicked in and save your work? :|