Jump to content

Working with UNDO command


Andrew1979

Recommended Posts

I have written some code that sets a 'Mark' in the 'UNDO' command before a LISP runs. My program is working as intended but if someone uses the program to draw something, then decides to type 'u' then enter, they will need to keep pressing the enter key/space bar many times to get back to before the LISP command started.

 

My questions is, is there a way for the user to only press the 'u' key and 'enter' key once to get back to before the program started?

I know they could type 'undo' then 'back' but I wanted the user to simple just type 'u'. I thought my code should work but it doesn't. The user has to keep pressing enter many times to get back to the start.

 

Any ideas?

 

This is the a part of how the code currently works:

 

[color=red]([color=royalblue]defun[/color][/color] getVariables [color=red]()[/color]
[color=red]([/color][color=royalblue]command[/color] [color=magenta]"undo" "mark"[/color][color=red])[/color]
[color=red]([/color][color=royalblue]command[/color] [color=magenta]"undo" "begin"[/color][color=red]) [/color]
[color=red]([/color][color=royalblue]setq[/color] temperr *error*[color=red])[/color]
[color=red]([/color][color=royalblue]setq[/color] *error* CCerror)  
[color=red]([/color][color=royalblue]setq[/color] CColdlayer    [color=red]([/color][color=royalblue]getvar[/color][color=magenta] "clayer"[/color][color=red]))[/color]
[color=red]([/color][color=royalblue]setq[/color] CColdpickbox   [color=red] ([/color][color=royalblue]getvar[/color][color=magenta] "pickbox"[/color][color=red]))[/color]
[color=red]([/color][color=royalblue]setq[/color] CColdcmdecho    [color=red]([/color][color=royalblue]getvar[/color] [color=magenta]"cmdecho"[/color][color=red]))[/color]
[color=red]([/color][color=royalblue]setq[/color] CColdosmode    [color=red]([/color][color=royalblue]getvar[/color] [color=magenta]"osmode"[/color]))
[color=red]([/color][color=royalblue]setq[/color] CColdorthomode    [color=red]([/color][color=royalblue]getvar[/color] [color=magenta]"orthomode"[/color][color=red]))[/color]
[color=red]([/color][color=royalblue]setvar[/color] [color=magenta]"cmdecho"[/color] [color=seagreen]0[/color][color=red])[/color]
[color=red]([/color][color=royalblue]setvar[/color] [color=magenta]"osmode"[/color] [color=seagreen]1[/color][color=red])[/color]  
[color=red]  )[/color]

[color=red]([/color][color=royalblue]defun[/color] setVariables [color=red]()[/color]
[color=red]([/color][color=royalblue]setvar[/color] [color=magenta]"pickbox"[/color] [color=seagreen]0[/color][color=red]) [/color] 
[color=red]([/color][color=royalblue]setvar[/color][color=magenta] "osmode"[/color] [color=seagreen]0[/color][color=red])[/color]
[color=red]([/color][color=royalblue]setvar[/color] [color=magenta]"blipmode"[/color] [color=seagreen]0[/color][color=red])[/color]
[color=red])[/color]

[color=red]([/color][color=royalblue]defun[/color] Restore [color=red]()[/color]
[color=red]([/color][color=royalblue]setvar[/color] [color=magenta]"clayer"[/color] CColdlayer[color=red])[/color]
[color=red]([/color][color=royalblue]setvar[/color][color=magenta] "pickbox"[/color] CColdpickbox[color=red])[/color]
[color=red]([/color][color=royalblue]setvar [/color][color=magenta]"cmdecho"[/color] CColdcmdecho[color=red])[/color]
[color=red]([/color][color=royalblue]setvar[/color] [color=magenta]"osmode"[/color] CColdosmode[color=red])[/color]
[color=red]([/color][color=royalblue]setvar[/color] [color=magenta]"orthomode"[/color] CColdorthomode[color=red])[/color]
[color=red]([/color][color=royalblue]command[/color][color=magenta] "undo" "end"[/color][color=red])[/color]
[color=red])[/color]

Link to comment
Share on other sites

I think I have worked out the problem. The code above works fine. What I was doing was calling the (Restore) function at the end of every different drawing function rather than adding it once to the main function that calls all the other functions for the program to work.....if that makes sense.

 

The new problem I have now though is that the 'u' command goes back to the start of the program, but the command prompt says:

 

Command: U
GROUP (Lisp Expression) (Lisp Expression) (Lisp Expression) (Lisp Expression

 

How do I hide the (Lisp Expression) coming up???

Link to comment
Share on other sites

While there is a vl_ cal to start an UNDO group, this is the vanilla version:

 

(defun SetUndo ()
(and (zerop (getvar "UNDOCTL"))
     (command "_.UNDO" "_ALL"))
(and (= (logand (getvar "UNDOCTL") 2) 2)
     (command "_.UNDO" "_CONTROL" "_ALL"))
(and (= (logand (getvar "UNDOCTL")  8)
     (command "_.UNDO" "_END"))
(command "_.UNDO" "_GROUP"))

 

Then your *error* should contain :

 

(setq  olderr *error*
     *error* (lambda (msg)
               (while (> (getvar "CMDACTIVE") 0)
                      (command))
               (and (/= msg "quit / exit abort")
                    (princ (strcat "\nError: *** " msg " *** ")))
               (and (= (logand (getvar "UNDOCTL")  8)
                    (command "_.UNDO" "_END" "_.U"))
               (restore))

Link to comment
Share on other sites

  • 1 year later...

I m having the same problem with this

Command: U
GROUP (Lisp Expression) (Lisp Expression) (Lisp Expression) (Lisp Expression

I m using too a grouped undo. In my defun function I begin with

 

(command-s "._BE")

and following is my *error* function

 

(defun *error* ( err_msg )
 
   (colb_f)
   (command-s "._undo" "_E")

   (if (or (= err_msg "Function cancelled") (= err_msg "quit / exit abort"))
       (princ)
       (princ (strcat "\nError: " err_msg))
   )
)

Everything 's working well, it's just that when I press "u" I get the annoying

(Lisp Expression) multiple times. I couln"t make out the solution from the example above. Any one can help how to suppress this?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...