Results 1 to 3 of 3

Thread: Error Handling

  1. #1
    Member jwf's Avatar
    Join Date
    Westminster, Co
    Login to Give a bone

    Default Error Handling

    Hopefully someone can help. We currently use our acaddoc.lsp to load all of our lisp. Within this doc there are two routines as well. The first (initerr) and the second (reset).
    INITERR stores some common variables. RESET will restore all of the stored variables in the initerr. These two commands run at the beginning(initerr) and at the end(reset) of our routines.
    The problem is, if you esc in the middle of a routine it will not restore your variables because you never reach the RESET command in that routine.
    (defun initerr ()
       (setq oldlayer (getvar "clayer"))
       (setq oldsnap (getvar "osmode"))
       (setq oldortho (getvar "orthomode"))
       (setq oldang (getvar "snapang"))
       (setq oldcol (getvar "cecolor"))
    (defun reset ()
       (setvar "clayer" oldlayer)
       (setvar "osmode" oldsnap)
       (setvar "orthomode" oldortho)
       (setvar "snapang" oldang)
       (setvar "dwgcheck" 1)
       (setvar "cecolor" oldcol)
    Those are the command in my acaddoc.lsp

    A sample Routine is:
    ;DLEADER.LSP  bgceDotLeader  (c)2004, Dragon Slayer
    (defun c:DLEADER  (/ *error*)
     (defun *Error* (msg)
      (print "Error: ")
      (print msg)
    (setvar "CMDECHO" 0)
    (setq z3 (getvar "texteval"))
    (setq z4 (getvar "clayer"))
    (setq z5 (getvar "cecolor"))
    (setq z6 (getvar "celtype"))
    (setq t1 (substr z4 1 1))
    (if (or (= t1 "M") (= t1 "F")) (setvar "clayer" "M-TEXT") ())
    (if (= t1 "E") (setvar "clayer" "E-TEXT") ())
    (if (= t1 "P") (setvar "clayer" "P-TEXT") ())
    (if (and (and (and (/= t1 "M") (/= t1 "P")) (/= t1 "E")) (/= (tblsearch "layer" "G-ANNO-TEXT") nil)) (setvar "clayer" "G-ANNO-TEXT") ())
    (setvar "celtype" "BYLAYER")
    (setvar "cecolor" "BYLAYER")
    (setvar "dimclrd" 256)
    (setvar "osmode" 0)
    (setvar "orthomode" 0)
    (setvar "dimasz" 0.054)
    (setvar "texteval" 1)
    (setq ss nil)
    (setvar "dimclrd" 7)
    (setvar "osmode" 512)
    (setq pt1 (getpoint "Select Arrowhead Point (Snap to line:  "))
    (if (/= (setq ss (ssget pt1)) nil)
           (setq lobj (ssname ss 0))
           (setq ldata (entget lobj))
           (if (/= (setq objcol (cdr (assoc 62 ldata))) nil)
               (setq objcol (cdr (assoc 62 ldata)))
                    (setq objlay (cdr (assoc 8 ldata)))
                    (SETQ OBJCOL (CDR (ASSOC 62 LAYERLIST)))
           (if (or (= objcol 1) (= objcol 5))
               (setvar "dimasz" (* (getvar "dimasz") 1.5))
    (acet-ql-set '((63 . 1)(61 . 0)(71 . 1)(68 . 1)(69 . 1)(68 . 0)(60 . 4)))
    (command "qleader" PT1 pause pause )
    (Setvar "texteval" z3)
    (setvar "cecolor" z5)
    (setvar "celtype" z6)
    ;end dLEADER.lsp
    How can I make it so when I esc in the middle it will default to my stored variables. The trick is I would to do it in my ACADDOC.LSP. I do not want to change 100's of routines. We are a MEP Consulting firm. Our menus have been customized alot during the past 7 years. Many lisp routines have been created.

    Thanks for any help I receive
    Last edited by RobertB; 2004-12-03 at 07:35 PM. Reason: I made edits here to show the fix clearly

  2. #2
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    0,0,0 The Origin
    Login to Give a bone

    Default Re: Error Handling

    Your individual routines do not contain a custom error handler so "reset" never gets called.

    This is the (old-fashioned) standard way to add an error handler -

    (defun myerror (s) ; If an error (such as CTRL-C) occurs
    ; while this command is active...
    (if (/= s "Function cancelled")
    (princ (strcat "\nError: " s))
    (setvar "cmdecho" ocmd) ; Restore saved modes
    (setvar "blipmode" oblp)
    (setq *error* olderr) ; Restore old *error* handler

    So you would need something along the lines of -

    (defun myerror (s) ; If an error (such as CTRL-C) occurs
    ;while this command is active...
    (if (/= s "Function cancelled")

    - added to each routine.

    I'm not a great programmer so don't take this code too literaly.

  3. #3
    The Silent Type RobertB's Avatar
    Join Date
    Seattle WA USA
    Login to Give a bone

    Exclamation Re: Error Handling

    In addition to the edits I made directly to your code, I wanted to attach a copy of an ATP I did a few years ago.
    Attached Files Attached Files

Similar Threads

  1. Error Handling
    By ticad02 in forum AutoLISP
    Replies: 16
    Last Post: 2009-12-21, 03:39 PM
  2. Error Handling
    By whattaz13 in forum AutoLISP
    Replies: 2
    Last Post: 2008-07-16, 01:03 PM
  3. Error Handling:
    By spencer.67965 in forum AutoLISP
    Replies: 4
    Last Post: 2004-09-15, 09:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts