Setting Variables back if User Cancelled Routine

Discussion in 'AutoCAD' started by sashk, Jul 30, 2003.

  1. sashk

    sashk Guest

    Hello All,

    I am not an expert in lisp, but I can do a few things. Here is my problem:

    Our lisp routines, when invoked, set some variables, and then when the routine is done, it will set them back. For example, this--> (setvar OLDOS (getvar "osmode")). And then, at the end of the routine, it will do this
    -->(setvar "osmode" OLDOS). Now, sometimes, people will cancel the routine right when it has been invoked. How can I make it so that if the user hits the ESC button, it will revert back to their settings?? Thanks
     
    sashk, Jul 30, 2003
    #1
  2. sashk

    sashk Guest

    Alex, it did not download. It says that there are no attachments. Can you re-load it??
     
    sashk, Jul 30, 2003
    #2
  3. (defun C:Test (/ *Error* oldHighlight)
    ;;; Error handler
    (defun *Error* (Err)
    (cond ((not Err))
    ((member Err '("Function cancelled" "quit / exit abort")))
    ((princ (strcat "\nError: " Err))
    (cond (*Debug* (vl-bt)))))
    (if oldHighlight (setvar "Highlight" oldHighlight))
    (princ))
    ;;; Main code
    (setq oldHighlight (getvar "Highlight"))
    (setvar "Highlight" 0)
    (command "._Erase" "_si" pause)
    ;;; Normal exit
    (*Error* nil))


    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | Alex, it did not download. It says that there are no attachments. Can you
    re-load it??
     
    R. Robert Bell, Jul 30, 2003
    #3
  4. You didn't follow my example real close, did you? ;-)

    1) Unless you *want* to overwrite the global error handler, it should be
    embedded in the main function, and declared as local.

    2) You are never saving the old status of any of your setvars. See my
    sample.

    3) You are never restoring your setvars in the error handler. You only
    pasted my error handler outside of your function and didn't modify it to fit
    the setvars you are concerned about.


    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | I see what you did. I should have paid more attention.
    | I pasted what I needed to in my routine, invoked the routine, then hit the
    ESC button, but it never set my variables back to how they were. Any ideas
    why??
    | Here is a sample routine that sets some variables. I ran the routine, and
    when it asked me to get something, I hit the ESC button. The variables did
    not set back to the way they were
    | SK
    |
     
    R. Robert Bell, Jul 30, 2003
    #4
  5. BTW, the Undo End should be in the error handler.


    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | I see what you did. I should have paid more attention.
    | I pasted what I needed to in my routine, invoked the routine, then hit the
    ESC button, but it never set my variables back to how they were. Any ideas
    why??
    | Here is a sample routine that sets some variables. I ran the routine, and
    when it asked me to get something, I hit the ESC button. The variables did
    not set back to the way they were
    | SK
    |
     
    R. Robert Bell, Jul 30, 2003
    #5
  6. sashk

    sashk Guest

    Robert, I noticed that right after I posted the thing. I am not an expert with lisp. Here is what I tried, but still no luck. Can you show me an example that would work? Here is mine. Can you modify it so it does work? Thanks
     
    sashk, Jul 30, 2003
    #6
  7. sashk

    sashk Guest

    Yes, I found the problem again. This is what happens when you come back from vacation. Brain seems to slow down. Why the "undo end" at the beginnig part of the routine? Or, is this really the end of the routine, even though it is at the top. If the user ran a long routine, and then did undo, will it really undo all of the steps, even though the "undo begin" is in the second part of the routine? (I hope that made sense.

    Robert, you have been a huge help. Thanks for your time and patience. I'm learning this stuff at time passes!
     
    sashk, Jul 30, 2003
    #7
  8. The end at the beginning (???) is in case another program failed to close
    their own undo group. That way you own code won't get grouped with the other
    program's.


    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | Yes, I found the problem again. This is what happens when you come back
    from vacation. Brain seems to slow down. Why the "undo end" at the beginnig
    part of the routine? Or, is this really the end of the routine, even though
    it is at the top. If the user ran a long routine, and then did undo, will it
    really undo all of the steps, even though the "undo begin" is in the second
    part of the routine? (I hope that made sense.
    | Robert, you have been a huge help. Thanks for your time and patience. I'm
    learning this stuff at time passes!
    |
     
    R. Robert Bell, Jul 30, 2003
    #8
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.