Author Topic: Undoing a routine...  (Read 2837 times)

0 Members and 1 Guest are viewing this topic.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Undoing a routine...
« on: March 31, 2004, 04:29:34 PM »
Is there a way to undo an entire lisp routine with one undo? Here  is my rod & shelf routine, and when it's done, if I undo, it steps thru the routine backwards...Is there something I can put in the routine so that if I'm undo-ing, it will treat what was done in the lisp as a single undo?

File can be downloaded above, and here is the code for visual here...
Code: [Select]

;;                RodShelf.lsp
;;          Created by Dominic Cesare
;;                 01/23/2004

;;======================
;;Start of Routine
;;======================

(prompt "\nType RODSHELF to run.....")

(defun c:RODSHELF()
  (setq temperr *error*)
  (setq *error* trap1)
  ;stores current echo setting
  (setq oldecho (getvar "cmdecho"))
  ;stores current layer
  (setq oldlayer (getvar "clayer"))
  (setvar "cmdecho" 0)
  (COMMAND "-LAYER" "M" "PL-CAB" "C" "9" "" "")
  (prompt "\nTRACE interior of closet.....")
  ; start pline
  (command "._pline")
  ; while active command
  (while (eq (logand (getvar "CmdActive") 1) 1)
    ; get user's input
    (command pause)
    ;_ closes while
    )
  (setq PL (entlast))
  ;gets side to offset
  (setq INT (getpoint "\nPICK POINT inside closet....." ))
  ;creating shelf line
  (command "offset" "12.0" PL INT "")
  (setq SHELF (entlast))
  ;creating rod line
  (command "offset" "10.0" PL INT "")
  (setq ROD (entlast))
  ;changing rod to correct layer and linetype
  (command "change" ROD "" "P" "LT" "CENTER2" "")
  (command "erase" PL "")
  ;sets echo to saved setting
  (setvar "cmdecho" oldecho)
  (setvar "clayer" oldlayer)
  (setq *error* temperr)
  (princ)
  )

(defun trap1 (errmsg)
  (command "u")
  (setvar "cmdecho" oldecho)
  (setvar "clayer" oldlayer)
  (setq *error* temperr)
  (prompt "Resetting System Variables...")
  (princ)
  )

;;======================
;;    End of Routine
;;======================
[/url]

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Undoing a routine...
« Reply #1 on: March 31, 2004, 04:49:56 PM »
How about (command "_undo" "mark") and (command "_undo" "back")
TheSwamp.org  (serving the CAD community since 2003)

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Undoing a routine...
« Reply #2 on: March 31, 2004, 05:17:33 PM »
Quote from: Mark Thomas
How about (command "_undo" "mark") and (command "_undo" "back")


I don't know...how about those?   :lol:  I will have to try those out.  I saw those when I was reading about error trapping.  I'll have to re-read.  Thank you Mark  :twisted:

Columbia

  • Guest
Undoing a routine...
« Reply #3 on: April 02, 2004, 09:44:47 AM »
I like to use...

Code: [Select]

(command "._undo" "begin")

;;; all your stuff

(command "._undo" "end")


I find that it's a little more predictable when it comes to collecting all of the stuff I want.

I guess you could say that it's just another way to skin the same cat.

On a side not here is the VLISP/Active-X method of accomplishing the same thing...

Code: [Select]

(vl-load-com)  ;; to obey all rules of this forum!!

(vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-ACAD-Object)))

;;; do whatever here

(vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-ACAD-Object)))


Hope this helps just a little...