Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AutoLISP Function Undo

2 views
Skip to first unread message

LifeThruOne

unread,
Aug 20, 2002, 3:50:40 PM8/20/02
to
Hello, I was just wondering if it's possible to undo an AutoLISP command
rather than each of the AutoCAD commands that the AutoLISP function calls.
For example, I have a function:
(defun c:draw2lines (/ p1)
(setq p1 (getpoint "Enter Point of intersection: "))
(command "_.line" (polar p1 0 5) (polar p1 0 -5) "")
(command "_.line" (polar p1 (/ pi 2) 5) (polar p1 (/ pi 2) 5) "")
)
And then in AutoCAD, I call "draw2lines", it asks for p.o.i., I give the
wrong point, so I undo. But I have to undo twice because it undos the line
command. Is there a way to undo the "draw2lines" command?
By the way, I'm working with functions that have a lot more commands than
just 2, and I don't even know if the function above is correct, it's just an
example.
If you can help, it would be much appreciated. Thanks in advance.


-Brandon

Mark Propst

unread,
Aug 20, 2002, 4:08:04 PM8/20/02
to
(defun c:draw2lines (/ p1)
(command "undo" "end");close open groups
(command "undo" "begin");begin this group

... rest of lisp

(command "undo" "end");close this groups
);end defun

also search google for using similar in error handler in case of esc during
running lisp


Joshua Tapp

unread,
Aug 20, 2002, 4:53:23 PM8/20/02
to
That's definitely a simpler way of doing it, but what I've gleaned off this
group is to consider everything. Of course, for personal routines the
simpler, shorter way is always best. But, as I find out happens, personal
routines make their way to more widely-used routines. This method you take
into consideration all the various settings of the system variable
"UNDOCTL". Of course, I still consider myself a newbie so anyone can
correct me here.

I received this from Jon Fleming back a couple of years ago, and although I
haven't checked it for consistency across the various versions of AutoCAD, I
have not had any problems with it. I've used it in R14, R2000, and ADT 3.3.

You should follow this method:

(defun yourroutine ( exprs / GEH_OldUndoCtl)
(GEH_UndoBegin)
(your functions)
(GEH_UndoEnd)
(princ)
)

And then at the end of your function paste this in:

;;; Start an UNDO GROUP. Originally from Tony Tanzillo, through
;;; Tim Morse, modified by Jon Fleming

;;; No useful return value.

;;; GEH_OldUndoCtl should be defined as a local variable in
;;; the calling function.

(defun GEH_UndoBegin (/)
;; If UNDO is not disabled ...
(if (not (= 0 (setq GEH_OldUndoCtl (getvar "UNDOCTL"))))
(progn
;; If it's set to only undo one command ...
(if (= 1 (boole 1 2 GEH_OldUndoCtl))
;; Change it
(command "._undo" "_control" "_all")
) ;_ end if
;; If auto-group for menu items is enabled ...
(if (= 1 (boole 1 4 GEH_OldUndoCtl))
(command "._undo" "_auto" "_off")
;; Change it
) ;_ end if
;; If a group is active ...
(if (= 1 (boole 1 8 GEH_OldUndoCtl))
;; End it
(command "._undo" "_end")
) ;_ end if
;; Start our group
(command "._undo" "_group")
) ;_ end progn
;; UNDO is disabled, OK, we won't do anything.
) ;_ end if
) ;_ end defun

;;; End an UNDO GROUP. Originally from Tony Tanzillo, through
;;; Tim Morse, modified by Jon Fleming

;;; No useful return value.

;;; GEH_OldUndoCtl should be defined as a local variable in the
;;; calling function.

(defun GEH_UndoEnd (/)
;; If UNDO is not disabled ...
(if (not (= 0 GEH_OldUndoCtl))
(progn
;; End our UNDO group
(command "._UNDO" "_END")
;; If we were set to undo only one command ...
(if (= 1 (boole 1 2 GEH_OldUndoCtl))
;; Restore that
(command "._undo" "_control" "_one")
) ;_ end if
;; If auto-group for menu items was enabled ...
(if (= 1 (boole 1 4 GEH_OldUndoCtl))
;; Enable it
(command "._UNDO" "_CONTROL" "_AUTO")
) ;_ end if
) ;_ end progn
;; UNDO is disabled, do nothing.
) ;_ end if
) ;_ end defun

--
Joshua Tapp
Intern in waiting
Dillman-Luvaas Architects
www.dillman-luvaas.com

"Mark Propst" <Mark@atrengDOTcom> wrote in message
news:81B5F25B42D48930...@in.WebX.maYIadrTaRb...

Jon Fleming

unread,
Aug 21, 2002, 8:25:23 AM8/21/02
to
Actually, in AutoCAD 2000 and above, I've been using:

(vla-StartUndoMark
(vlax-get-property
(vlax-get-acad-object)
"ActiveDocument"
)
)
.
.
.
(vla-EndUndoMark
(vlax-get-property
(vlax-get-acad-object)
"ActiveDocument"
)
)

jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services

In article <53170AA3BDE6D537...@in.WebX.maYIadrTaRb>, Joshua Tapp
wrote:

Eric Schneider

unread,
Aug 21, 2002, 12:55:52 PM8/21/02
to
Jon,

Why do you prefer VLAX over VLA?

(vlax-get-property
(vlax-get-acad-object)
"ActiveDocument"
)

vs.:

(vla-getActiveDocument (vlax-get-acad-object))
--

Regards,
Eric S.
A2k/W2k


Jon Fleming

unread,
Aug 22, 2002, 8:20:40 AM8/22/02
to
I don't really prefer one over the other, it's just that the source
from which I copied the technique (I've forgotten exactly where I got
it) did it that way.

jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services

In article <AF4C4946B64C7230...@in.WebX.maYIadrTaRb>, Eric

0 new messages