undo custom lisp?

Discussion in 'AutoCAD' started by C Witt, Jun 29, 2004.

  1. C Witt

    C Witt Guest

    ok question for you guys..

    we have one lisp in particular that does anywhere from 20-60 commands
    when run.. the problem being.. if we need to undo.. we have to undo
    each step of the lisp and that is a pain in the a$.

    Is there a way of changing it so one undo will "undo" everything that
    the lisp did, regardless of how many commands were done??

    TIA.
     
    C Witt, Jun 29, 2004
    #1
  2. C Witt

    C Witt Guest

    it's not something that "can" be done in parts.. it's all or nothing.
    the reason for the differing # of commands is based on the current
    drawing standards and what the user is trying to do.. (we like to keep
    the user out of the equation).
     
    C Witt, Jun 29, 2004
    #2
  3. C Witt

    C Witt Guest

    can that be done in the long run though?..

    ie:
    opens drawing..
    spends 15 min drawing..
    runs "the" lisp..
    spends 20 min drawing..

    wait damn.. he needs to undo the last 25+- minutes worth ..
    hits undo...
    going fine.. hist the lisp.. now has to undo everything that the lisp
    did..

    ...


    will that "mark" idea work?
    what if the lisp ends up being run more than once.. if you need to undo
    both you lose the ability to undo the first one with the "mark" ..

    you see the problem?
     
    C Witt, Jun 29, 2004
    #3
  4. C Witt

    Barr Guest

    I mean like this:

    (defun c:routine ()
    (command "UNDO" "M")
    (do your thing, do 150 things til the cows come home)
    )

    If you really hate what just happened, UNDO BACK takes you to the point when you
    still liked what you'd done. (I just tested it with a lisp that changed the
    drawing 1256 times). Undo Back took it back to the point just prior to the lisp.
    -doug
     
    Barr, Jun 29, 2004
    #4
  5. C,

    You might want to look at a book; Visual Lisp: A Guide to Artful
    Programming by Phil Kreiker.

    His book looks at this very thing.

    W. Kirk Crawford
    Rochester Hills, Michigan
     
    W. Kirk Crawford, Jun 29, 2004
    #5
  6. C Witt

    C Witt Guest

    hmm.. i've been using "AutoLISP Programming Principles and Techniques"
    Rod Rawls/Mark Hagen
     
    C Witt, Jun 29, 2004
    #6
  7. C Witt

    Paul Turvill Guest

    (defun C:YourCommand ( )
    (command "_.undo" "_be")
    (do your 20-60 things)
    (command "_.undo" "_e")
    )

    Now a U command will undo everything between (command "_.undo" "_be") and
    (command "_.undo" "_e").
    ___
     
    Paul Turvill, Jun 29, 2004
    #7
  8. C Witt

    John Uhden Guest

    This is sorta the standard way the kind people 'round here use to handle errors
    and undos. Credits goes to Eric Schneider, Robert Bell, Doug Broad, et al.
    Notice how the *error* function and original variables are localized. There are
    more robust versions available by doing a search for *error*, but this oughta
    help a little.

    (defun c:Whatever (/ *error* cmdecho Doc and_whatever_else)
    (vl-load-com)
    (setq cmdecho (getvar "cmdecho"))
    (setq Doc (vla-get-ActiveDocument (vlax-get-acad-object)))
    (defun *error* (error)
    (setvar "cmdecho" cmdecho)
    (vla-endundomark Doc)
    (cond
    ((not error))
    ((wcmatch (strcase error) "*QUIT*,*CANCEL*"))
    (1 (princ (strcat "\nERROR: " error)))
    )
    (princ)
    )
    (vla-endundomark Doc)
    (vla-startundomark Doc)
    (setvar "cmdecho" 0)
    (command "_.expert" (getvar "expert")) ;; only in case your function doesn't
    use (command) elsewhere,
    ;; otherwise you'll see that annoying double "Command: " echo to the text
    screen.
    ;; Your code goes here
    (*error* nil)
    )

    WARNING: The ActiveX StartUndoMark method is equivalent to a (command "_.Undo"
    "_Begin). You can not use any (command "_.Undo" "_Mark") calls within a
    Begin...End group.
     
    John Uhden, Jun 29, 2004
    #8
  9. No need to. The Start/EndUndoMark methods actually use
    the UNDO subcommands under the hood.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 29, 2004
    #9
  10. To put it more precisely, there is absolutely no point
    to using the ActiveX methods for starting/ending UNDO
    groups in LISP. They exist primarily for use by VBA and
    ActiveX clients.

    In LISP, using (command "._UNDO" "_Begin"/"_End") is
    no different than calling the ActiveX methods, because
    that is exactly what they're doing.




    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 29, 2004
    #10
  11. C Witt

    Jeff Mishler Guest

    However, using the (vla- methods do not require the
    storing/setting/restoring of the cmdecho variable to suppress the echoing of
    the undo commands. This is why I started using them.

    IMHO,
    Jeff

     
    Jeff Mishler, Jun 29, 2004
    #11
  12. Why not live CMDECHO = 0?
     
    Marc'Antonio Alessi, Jun 29, 2004
    #12
  13. C Witt

    John Uhden Guest

    Except if UndoCtl has been set to 0, in which case (command "_.Undo" "_Begin")
    will cause an error, whereas (vla-xxxUndoMark) won't.

    Before ActiveX, I used to use the following ugly functions:
    (defun @undo_group ()
    ;; added "_.Undo" "_End" 3-12-98 based on troubleshooting with Guy Morris
    (if (= (logand 3 (getvar "undoctl")) 1)
    (progn
    (if (/= (getvar "cmdecho") 0)(setvar "cmdecho" 0))
    (command "_.Undo" "_End" "_.Undo" "_BEgin")
    )
    )
    )
    (defun @undo_end ()
    (if (= (logand 8 (getvar "undoctl")) 8)
    (progn
    (if (/= (getvar "cmdecho") 0)(setvar "cmdecho" 0))
    (command "_.Undo" "_End")
    )
    )
    )

    ActiveX is cleaner looking to me and doesn't need any attention to cmdecho.
     
    John Uhden, Jun 29, 2004
    #13
  14. I've yet to see any compelling reason to save/restore CMDECHO.

    I just turn it off.



    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning

     
    Tony Tanzillo, Jun 29, 2004
    #14
  15. Common sense would seem to suggest that if code depends on
    UNDO groups to ensure that changes made by an application
    that subsequently fails are not left intact, and UNDOCTL is
    off, then the code should turn it on (and off again once its
    finished). I believe that's the proper and sound way to deal
    with UNDOCTL=0.




    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 29, 2004
    #15
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.