error trap

Discussion in 'AutoCAD' started by Jan van de Poel, Feb 14, 2005.

  1. Hi,
    been using a sort of error trap for years now but the version i have seems
    to 'forget' to replace user settings like Osmode, Orthomode etc.

    Does anyone of you Guru's have a error trap that does work with these
    settings?

    user settings are something like these:
    (SETQ
    cmd (GETVAR "cmdecho")
    ort (GETVAR "orthomode")
    osm (GETVAR "osmode")
    bpm (GETVAR "blipmode")
    scl (GETVAR "dimscale")
    )

    They should be reset to their original values if a error or Cancel occurs.
    How to do this?

    This is my error trap:
    (defun *cng_err* (msg)
    (if (/= msg "Function cancelled")
    (if (= msg "quit / exit abort")
    (princ)
    (princ (strcat "\nError: "msg))
    )
    )
    (setq *error* *err_old* *err_old* nil)
    (princ)
    )
    I suppose its possible to use (progn (setq *error* *err_old* *err_old* nil)
    ('reset old values') )
    until now no succes with it.


    Regards,
    Jan
     
    Jan van de Poel, Feb 14, 2005
    #1
  2. Jan van de Poel

    Alaspher Guest

    As variant:
    Code:
    (defun template (/ *error* old-sets)
    (defun *error* (msg)
    (vl-cmdf) ;_ break any command
    (pl:setvars old-sets) ;_ restore old values
    (princ (strcat "\nError: " msg))
    (princ)
    )
    (setq old-sets (pl:setvars
    '(("cmdecho" 0) ;_ format: (<varname> <new value>)
    ("orthomode") ;_ or (<varname>) - only get
    ("osmode" 0)
    ("blipmode" 0)
    ("dimscale" 1.0)
    )
    ) ;_ add/remove your variables
    )
    ;;; ------ start your code ------
    
    (getpoint "\nPick any point: ") ;_ for example
    
    ;;; ------- end your code -------
    (pl:setvars old-sets) ;_ restore old values
    (princ)
    )
    
    (defun pl:setvars (varlst)
    (if varlst
    (mapcar (function
    (lambda (a / tmp res)
    (setq res (list (setq tmp (car a)) (getvar tmp)))
    (if (cadr a)
    (vl-catch-all-apply (function setvar) a)
    )
    res
    )
    )
    varlst
    )
    )
    )
    Best regards!
     
    Alaspher, Feb 14, 2005
    #2
  3. Jan van de Poel

    Joe Burke Guest

    Jan,

    I think you should post a complete function with error handler which demonstrates the
    problem. We can't know what's going on looking at the error handler alone.

    Joe Burke
     
    Joe Burke, Feb 14, 2005
    #3
  4. Jan van de Poel

    ECCAD Guest

    Jan,
    Revise your error trap like this:

    (defun *cng_err* (msg)
    (if (/= msg "Function cancelled")
    (if (= msg "quit / exit abort")
    (princ)
    (princ (strcat "\nError: "msg))
    )
    )
    ;reset vars
    (if cmd (setvar "CMDECHO" cmd))
    (if ort (setvar "ORTHOMODE" ort))
    (if osm (setvar "OSMODE" osm))
    (if bpm (setvar "BLIPMODE" bpm))
    (if scl (setvar "DIMSCALE" scl))
    ;
    (setq *error* *err_old* *err_old* nil)
    (princ)
    )

    Bob
     
    ECCAD, Feb 14, 2005
    #4
  5. Thanks guys,
    i'll give it a try.

    Jan
     
    Jan van de Poel, Feb 15, 2005
    #5
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.