Error trap and undo

Oct 16, 2003 4 Replies

I guess that I am misunderstanding the use of undo group, I am using the following the following error trap to try to reset the drawing back to it's original state.



If the function runs the (command "layer" "s" "P-FIXT-N" "") or reaches the second "-insert" command it simply does an undo 1 completely ignoring the group, when the "esc" key is pressed. If the make layer command was run and "esc" is pressed before the second "-insert", the error handler is successful. When the command is completed successfully an undo acts as a group. Is there an explanation and/or work around for this?



In addition can anyone recommend a book that has in depth coverage of autolisp concerning matters like this?



Thanks Cliff


(defun c:test ()



(defun error_trap (errormessage) (command "undo" "end") (command "undo" "1") (setq *error* error_back) (graphscr) (princ) )



(setq error_back *error*) (setq *error* error_trap) (setvar "cmdecho" 1) (command "undo" "group")



(if (tblsearch "LAYER" "P-FIXT-N") (command "layer" "s" "P-FIXT-N" "") (command "layer" "m" "P-FIXT-N" "c" "3" "P-FIXT-N" "lt" "CONTINUOUS" "P-FIXT-N" "") )



(princ "\nSelect insertion point for block: ") (command "-insert" "pipedrop" "s" (getvar "dimscale") pause nil) (princ "\nRotation angle: ") (command "-insert" "pipedrop" "s" (getvar "dimscale") (getvar "lastpoint") pause)



(command "undo" "end") (setq *error* error_back) )



Output: .................... Command: undo Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back] : end Command: undo Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back] : 1 -INSERT Command:


following the following error trap to try to reset the

second "-insert" command it simply does an undo 1

layer command was run and "esc" is pressed before the

completed successfully an undo acts as a group. Is there an

concerning matters like this?

Cliff,

I didn't see an UNDO BEGIN anywhere in your code. I don't do as much error trapping as I should, so don't consider me a good source of info for this particular topic. In some of my routines, however, I do something like:

(command "._UNDO" "Begin")

;code is all here

(command "._UNDO" "End")

I th> I guess that I am misunderstanding the use of undo group, I am using the

following the following error trap to try to reset the

second "-insert" command it simply does an undo 1

layer command was run and "esc" is pressed before the

completed successfully an undo acts as a group. Is there an

concerning matters like this?

I should have mentioned in the post that I tried undo begin as well as undo group with the same effects. Is their a real difference between the two? Cliff

following the following error trap to try to reset the

second "-insert" command it simply does an undo 1

layer command was run and "esc" is pressed before the

completed successfully an undo acts as a group. Is there an

autolisp concerning matters like this?

group with the same effects. Is their a real difference

Off hand, I can't answer that definitively. It's been a while since I've fooled with that, so I'll read a little before I speak further.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required