how to catch escape or cancel?

Discussion in 'AutoCAD' started by Jan van de Poel, Jul 2, 2004.

  1. Hi,
    i've got an customized command like 'mirror'.
    Works great as it is, however when a user cancels the command while active
    the osnaps are not restored.

    The command is like this:
    ^c^c^p(setq osm(getvar "osmode"));(setvar"osmode"
    0);SELECT;au;\MIRROR;p;;\\N;(setvar"osmode"osm);^p

    The goal is: keep the osnaps as they are even when a user chooses another
    command or even cancels this one.

    Can it be done?

    Jan
     
    Jan van de Poel, Jul 2, 2004
    #1
  2. Jan van de Poel

    spencer1971 Guest

    I would usually start a lisp file with the following:-

    (defun MyError ()
    (setvar "clayer" clay)
    (setvar "osmode" oldos)
    (setvar "cmdecho" cmde)
    )

    And then define the error command within the main part of the routine using the following:-

    (setq *ERROR* MyError)
    (setq Clay (getvar "clayer"))
    (setq oldos (getvar "osmode"))
    (setq cmde (getvar "cmdecho"))

    This seems to work for me although being new to lisp writing I'd be interested to find out if this is the most practical way of doing things


    Spence
     
    spencer1971, Jul 2, 2004
    #2
  3. Jan van de Poel

    Tom Smith Guest

    Search this NG or Google, it has been discussed at great length.
     
    Tom Smith, Jul 2, 2004
    #3
  4. Jan van de Poel

    ECCAD Guest

    Spence,
    Let me suggest - checking the var's..
    Like:
    (defun MyError ()
    (if clay (setvar "clayer" clay))
    (if oldos (setvar "osmode" oldos))
    (if cmde (setvar "cmdecho" cmde))
    )

    If not set..causes yet another error..

    Bob
     
    ECCAD, Jul 2, 2004
    #4
  5. Jan van de Poel

    spencer1971 Guest

    Bob,
    Why would you need to check for the variables.
    Is It in case the lisp is aborted before the variables are set.
    I'm not questioning that you are right, but just trying to understand the reason for checking vars,

    Many thanks for your help

    Spence
     
    spencer1971, Jul 2, 2004
    #5
  6. Jan van de Poel

    zeha Guest

    Jan,

    The way i do is the follow
    I use not the setvar osmode to none.

    If the user cancel the command, all setting be the same because there is no difference

    Why using osmode?
    This is because while autocad draws and snap's to the current osnap settings rather than the exactly given point
    i.e if the given point is 1,1 and osmode is set to endpoint and thera is a object drawn to 0,0 the point witch automaticly is given by (getvar "lastpoint") switch to the endpoint 0,0 and not to 1,1

    Example
    (command "._Line" "_Non" "1,1" "_Non" "100,1" "")

    (command "._Line" "0,0" "_Non" "100,0" "")



    I think it's not necessary to set osmode 0 in the macro because the user has it set to his preference but i am not sure

    Even when it's necessary i use the snap _non (this is equal to F3) for given point


    Experience the macro without the osmode command's

    Evenso you could osmode set to (setvar "osmode" 16493) it equivalent to osnap off (F3) when the user cancel the command it can restored with F3 osnap on.

    Cheers
     
    zeha, Jul 4, 2004
    #6
  7. Jan van de Poel

    ECCAD Guest

    It is unlikely, but possible that operator could hit escape between lines:
    (setq Clay (getvar "clayer"))(setq oldos (getvar "osmode"))

    Bob
     
    ECCAD, Jul 4, 2004
    #7
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.