Author Topic: Error handler help needed  (Read 5361 times)

0 Members and 1 Guest are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Error handler help needed
« on: August 09, 2006, 01:10:38 PM »
Ok I have this program that will blink a selected layer.  The problem is that if I hit esc the program will not go to the Reset_env sub to reset the layer color etc.  What it the problem I've been looking at this thing for about an hour.


hl.lsp
Code: [Select]
;;; ------------------------------------------------------------------------
;;;    HL.LSP Version 1.1
;;;
;;;    Copyright (C) SEPTEMBER, 2001
;;;    Timothy G. Spangler
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice appear in all supporting documents.
;;;
;;;    Blinks Selected Layer
;;;
;;; ------------------------------------------------------------------------
(defun wait (seconds / stop)           ; Pause Routine Thanks to Tony
                                       ; Tanzillo
  (setq stop (+ (getvar "DATE") (/ seconds 86400.0)))
  (while (> stop (getvar "DATE"))
    (princ)
  )
)
;;; End defun
;;;
(defun c:hl (/ *error* blink hlini obj off old_cmdecho old_error old_layer
               old_regenmode old_uscicon on path version
            )                          ; Set the Env for Use
                                      
  ;; Error Handling Routine
(defun *error* (Msg)

(if (not (member Msg '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase Msg) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "cmdactive"))
(command)
)
(RESET_ENV)
(princ)
)

(command "_undo" "BE")
  (setq old_cmdecho (getvar "cmdecho"))
  (setq old_layer (getvar "clayer"))
  (setq old_regenmode (getvar "regenmode"))
  (setq old_uscicon (getvar "ucsicon"))
  (setvar "cmdecho" 0)
  (setvar "regenmode" 0)
  (setvar "ucsicon" 0)
  (setq path "C:/Acad Toolbox/Menu Files/Layer Tools/") ;;<-------CHANGE THIS HARD CODED PATH
  (setq obj (car (entsel "\nPick layer to HIGHLIGHT or [ENTER] for Options: ")))
  (if (findfile (strcat path "HL.ini")) ; Begin if
    (progn                             ; Retrieves information from INI
                                       ; file
      (princ "\nRetrieving Configuration...Please Wait. ")
      (wait 0.5)
      (setq hlini (open (strcat path "HL.ini") "r"))
      (read-line hlini)
      (setq version (read-line hlini))
      (read-line hlini)
      (read-line hlini)
      (setq on (atoi (read-line hlini)))
      (read-line hlini)
      (setq off (atoi (read-line hlini)))
      (read-line hlini)
      (setq blink (atof (read-line hlini)))
      (close hlini)
    )                                  ; End progn
    (progn                             ; Creates INI file
      (princ "\nCreating Config file...Please Wait. ")
      (wait 0.5)
      (setq hlini (open (strcat path "HL.ini") "w"))
      (write-line "Configuration File for Highlight Layer Lisp" hlini)
      (write-line "Highlight Layer v1.1  " hlini)
      (write-line "\nBlink On" hlini)
      (write-line "7" hlini)
      (write-line "Blink Off" hlini)
      (write-line "250" hlini)
      (write-line "Blink Speed" hlini)
      (write-line "0.5" hlini)
      (close hlini)
      (setq on 7)
      (setq off 250)
      (setq blink 0.5)
      (setq version "Highlight Layer v1.1  ")
    )                                  ; End progn
  )                                    ; End if
  (pick)
)
;;; End defun
;;;
(defun dialog (/ dcl_id end_dialog)    ; Starts Dialog Session
  (setq DCL_ID (load_dialog "hl.dcl"))
  (if (not (new_dialog "hl" DCL_ID))
    (exit)
  )                                    ; End if
  (image)
  (set_tile "message" version)
  (set_tile "blinker" (rtos blink 2 2))
  (action_tile "blinkon" "(done_dialog 5)")
  (action_tile "blinkoff" "(done_dialog 6)")
  (action_tile "blinker" "(setq blink (atof $value))")
  (action_tile "accept" "(done_dialog 3)")
  (action_tile "cancel" "(done_dialog 4)")
  (setq end_dialog (start_dialog))
  (cond                                ; Begin cond
    ((= end_dialog 5)                  ; Sets blink on color
      (setq on (acad_colordlg 7 nil))
      (dialog)
    )
    ((= end_dialog 6)                  ; Sets blink off color
      (setq off (acad_colordlg 7 nil))
      (dialog)
    )
    ((= end_dialog 3)                  ; <OK>
      (save_ini)
      (setq obj (car (entsel "\nPick layer to HIGHLIGHT: ")))
      (pick)
    )
    ((= end_dialog 4)                  ; <CANCEL>
      (princ "\n User Cancelled!")
    )
  )                                    ; End cond

)
;;; End defun
;;;
(defun pick (/ layr layrcolor)         ; Allows user to select object

  (if (= (type obj) nil)
    (dialog)
    (progn                             ; Begin progn
      (setq layr (cdr (assoc 8 (entget obj))))
      (setq layrcolor (cdr (assoc 62 (tblsearch "layer" layr))))
      (repeat 5                        ; Begin repeat
        (command ".layer" "s" layr "c" on "" "")
        (wait blink)
        (command ".layer" "s" layr "c" off "" "")
        (wait blink)
      )                                ; End repeat
      (princ (strcat "\nThe highlighted layer was:   " layr))
    )                                  ; End progn
  )                                    ; End if
  (reset_env)
)
;;; End defun
;;;
(defun image (/ offcol offhgt offwid oncol onhgt onwid) ; Sets blink on/off
                                       ; color swatches
  (setq onwid (dimx_tile "blinkon"))   ; Begin Blink ON
  (setq onhgt (dimx_tile "blinkon"))
  (setq oncol on)
  (start_image "blinkon")
  (fill_image 0 0 onwid onhgt oncol)
  (end_image)                          ; End Blink ON
  (setq offwid (dimx_tile "blinkoff")) ; Begin Blink OFF
  (setq offhgt (dimx_tile "blinkoff"))
  (setq offcol off)
  (start_image "blinkoff")
  (fill_image 0 0 offwid offhgt offcol)
  (end_image)                          ; End Blink OFF

)
;;; End defun
;;;
(defun save_ini (/ hlini)              ; Saves Confinguration to INI file
  (if (findfile(strcat path "HL.ini")) ; Begin if
    (progn                             ; Begin progn
      (princ "\nSaving Configuration...Please Wait. ")
      (wait 0.5)
      (setq hlini (open (strcat path "hl.ini") "w"))
      (write-line "Configuration File for Highlight Layer Lisp" hlini)
      (write-line "Highlight Layer v1.1  " hlini)
      (write-line "\nBlink On" hlini)
      (write-line (rtos on 2 0) hlini)
      (write-line "Blink Off" hlini)
      (write-line (rtos off 2 0) hlini)
      (write-line "Blink Speed" hlini)
      (write-line (rtos blink 2 2) hlini)
      (close hlini)
    )                                  ; End progn
  )                                    ; End if

)
;;; End defun
;;;
(defun RESET_ENV (/)                   ; Reset env
 
  (command "_undo" "END")
(setvar "clayer" old_layer)
  (setvar "regenmode" old_regenmode)
  (setvar "ucsicon" old_uscicon)
  (command ".layer" "c" layrcolor layr "") 
  (setvar "cmdecho" old_cmdecho)
  (princ)
)
;;; End defun
;;;
;;; Echos to the command line
(princ "\nHighlight Layer v1.1 \n(c)Timothy Spangler, \nSeptember, 2001....loaded.")
;;; End echo

hl.dcl
Code: [Select]
/// ------------------------------------------------------------------------
///    HL.DCL Version 1.0
///
///    Copyright (C) SEPTEMBER, 2001
///    Timothy G. Spangler
///
///    Permission to use, copy, modify, and distribute this software
///    for any purpose and without fee is hereby granted, provided
///    that the above copyright notice appears in all copies and
///    that both that copyright notice and the limited warranty and
///    restricted rights notice below appear in all supporting
///    documentation.
///
///    Used to get information for HL.lsp
///
/// ------------------------------------------------------------------------

hl:dialog{
label = "Layer Highlight Options";
:boxed_column{
label = "On/Off Colors";
:row{
:text{
label = "Blink On Color";
}
:image_button{
key = "blinkon";
width = 2;
aspect_ratio = 2.5;
}
}
:row{
:text{
label = "Blink Off Color";
}
:image_button{
key = "blinkoff";
width = 2;
aspect_ratio = 2.5;
}
}
}
:boxed_column{
label = "Blinking Speed";
spacer_0;
:edit_box{
label = "Blinking Speed (sec):";
key = "blinker";
width = 2;
fixed_width = true;
}
spacer_1;
}
:boxed_row{
    label = "Message...";
      :text{
      key = "message";
     height = 3;
      }
    }
:row{
ok_cancel;
}
}

hl.ini
Code: [Select]
Configuration File for Highlight Layer Lisp
Highlight Layer v1.1 

Blink On
41
Blink Off
161
Blink Speed
0.25
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Error handler help needed
« Reply #1 on: August 09, 2006, 01:26:09 PM »
What prints to the comamnd line when you hit escape?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #2 on: August 09, 2006, 01:26:39 PM »
quick guess --

Code: [Select]
...
(   (= end_dialog 4)
    (princ \nLoser Cancelled!")
    (RESET_ENV)
)
...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Error handler help needed
« Reply #3 on: August 09, 2006, 01:28:52 PM »
This is what i get

... Program Cancelled ...; error: An error has occurred inside the *error*
functionFunction cancelled

And I not getting anything reset.


/edit: darn fat fingers
« Last Edit: August 09, 2006, 01:32:36 PM by TimSpangler »
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #4 on: August 09, 2006, 01:33:13 PM »
Make the first line in your err handler (vl-bt), reload, re-run and then tell us what you see when you hit <esc>.

Side bet: (command ".layer" "c" layrcolor layr "") call in the reset func, but it's a blind guess.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Error handler help needed
« Reply #5 on: August 09, 2006, 01:38:36 PM »
This is waht the backtrace gives me:

Backtrace:
[0.58] (VL-BT)
[1.54] (*ERROR* "Function cancelled")
[2.49] (_call-err-hook #<SUBR @086e8488 *ERROR*> "Function cancelled")
[3.43] (sys-error "Function cancelled")
:ERROR-BREAK.38 nil
[4.35] (sys-rtcan-hook)
:KBD-BREAK.31 :KBD-BREAK
[5.28] (WAIT 0.25)
[6.23] (PICK)
[7.19] (C:HL)
[8.15] (#<SUBR @086e8c58 -rts_top->)
[9.12] (#<SUBR @087c2334 veval-str-body> "(C:HL)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

... Program Cancelled ...; error: An error has occurred inside the *error*
functionFunction cancelled

I believe that it is in the Reset sub.  When I comment that line out it just cancels like it should.

<going to look in there>
 Be right back
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #6 on: August 09, 2006, 01:42:53 PM »
Code: [Select]
(defun RESET_ENV ( )
 
    (command "_undo" "END")                  ;;  Is undo enabled? Is an undo sequence uncapped?
    (setvar "clayer" old_layer)              ;;  Are varaibles old_layer
    (setvar "regenmode" old_regenmode)       ;;                old_regenmode
    (setvar "ucsicon" old_uscicon)           ;;                old_uscicon
    (command ".layer" "c" layrcolor layr "") ;;                layrcolor, layr
    (setvar "cmdecho" old_cmdecho)           ;;                old_cmdecho
    (princ)                                  ;;  properly set / valid values?

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Error handler help needed
« Reply #7 on: August 09, 2006, 01:43:42 PM »
Make the first line in your err handler (vl-bt), reload, re-run and then tell us what you see when you hit <esc>.

Side bet: (command ".layer" "c" layrcolor layr "") call in the reset func, but it's a blind guess.
I second this.  You may have to test that both variables are set before you issue the command.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Error handler help needed
« Reply #8 on: August 09, 2006, 03:00:40 PM »
Well tried just about everything I can think of.  nothing seems to work.  I created a sub to set everything before the errhandler.  I t seems that if I put anything having to do with (command.... it dumps.  Not sure why.

Don't have anymore time today (well at least til 5:00) to play with it.  I may just rewrite it with some vl stuff.  This thing was originally written in 1999, this was one of my first programs that i wrote.

Thanks guys, if you spot something jsut let me know

ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #9 on: August 09, 2006, 03:13:37 PM »
If the error handler is called before the dialog is closed that would cause it to kack -- you cannot invoke command whilst a dialog is active.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Error handler help needed
« Reply #10 on: August 09, 2006, 03:20:21 PM »
The dialog only opens if enter is hit instead of the selection of an object.  It is only used to set preferances i.e. blinking colors and blinking speed etc., so under normal circumstances there is no dialog.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Error handler help needed
« Reply #11 on: August 09, 2006, 07:35:39 PM »
Well, I know I've seen dicussions on this before, but I sure can't find anything on it now. But from some testing I've done here, you cannot reliably use (command) within the (*error*) function.

I've rearranged your code so all functions are inside of the main routine (this ensures they all reference the same *error* function) and modified the UNDO marks & resetting of the layer color to use ActiveX instead of (command). It seems to work properly now.
Code: [Select]
;;; ------------------------------------------------------------------------
;;;    HL.LSP Version 1.1
;;;
;;;    Copyright (C) SEPTEMBER, 2001
;;;    Timothy G. Spangler
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice appear in all supporting documents.
;;;
;;;    Blinks Selected Layer
;;;
;;; ------------------------------------------------------------------------
(defun c:hl (/ *error*     blink hlini
     obj off      old_cmdecho old_error
     old_layer old_regenmode old_uscicon
     on path      version LAYR
     LAYRCOLOR wait doc
    ) ; Set the Env for Use
  (defun RESET_ENV () ; Reset env

   ; (command "_.undo" "_END")
    (setvar "clayer" old_layer)
    (setvar "regenmode" old_regenmode)
   ;(setvar "ucsicon" old_uscicon)
    (if layr
      ;(command ".layer" "c" layrcolor layr "")
      (vla-put-color (vla-item (vla-get-layers doc) layr) layrcolor)
    )
    (setvar "cmdecho" old_cmdecho)
    (vla-endundomark doc)
  )

  ;; Error Handling Routine
  (defun *error* (Msg)

    (if (not
  (member Msg '("Function cancelled" "quit / exit abort"))
)
      (princ (strcat "\n*** Program Error: " (strcase Msg) " ***"))
      (princ "\n... Program Cancelled ...")
    )
    (RESET_ENV)
    (princ)
  )
  (defun wait (seconds / stop) ; Pause Routine Thanks to Tony
; Tanzillo
    (setq stop (+ (getvar "DATE") (/ seconds 86400.0)))
    (while (> stop (getvar "DATE"))
      (princ)
    )
  )

;;;
  (defun dialog (/ dcl_id end_dialog) ; Starts Dialog Session
    (setq DCL_ID (load_dialog "hl.dcl"))
    (if (not (new_dialog "hl" DCL_ID))
      (exit)
    ) ; End if
    (image)
    (set_tile "message" version)
    (set_tile "blinker" (rtos blink 2 2))
    (action_tile "blinkon" "(done_dialog 5)")
    (action_tile "blinkoff" "(done_dialog 6)")
    (action_tile "blinker" "(setq blink (atof $value))")
    (action_tile "accept" "(done_dialog 3)")
    (action_tile "cancel" "(done_dialog 4)")
    (setq end_dialog (start_dialog))
    (cond ; Begin cond
      ((= end_dialog 5) ; Sets blink on color
       (setq on (acad_colordlg 7 nil))
       (dialog)
      )
      ((= end_dialog 6) ; Sets blink off color
       (setq off (acad_colordlg 7 nil))
       (dialog)
      )
      ((= end_dialog 3) ; <OK>
       (save_ini)
       (setq obj (car (entsel "\nPick layer to HIGHLIGHT: ")))
       (pick)
      )
      ((= end_dialog 4) ; <CANCEL>
       (princ "\n User Cancelled!")
      )
    ) ; End cond

  )
;;; End defun
;;;
  (defun pick () ; Allows user to select object

    (if (= (type obj) nil)
      (dialog)
      (progn ; Begin progn
(setq layr (cdr (assoc 8 (entget obj))))
(setq layrcolor (cdr (assoc 62 (tblsearch "layer" layr))))
(repeat 5 ; Begin repeat
  (command ".layer" "s" layr "c" on "" "")
  (wait blink)
  (command ".layer" "s" layr "c" off "" "")
  (wait blink)
) ; End repeat
(princ (strcat "\nThe highlighted layer was:   " layr))
      ) ; End progn
    ) ; End if
    (reset_env)
  )
;;; End defun
;;;
  (defun image (/ offcol offhgt offwid oncol onhgt onwid)
; Sets blink on/off
; color swatches
    (setq onwid (dimx_tile "blinkon")) ; Begin Blink ON
    (setq onhgt (dimx_tile "blinkon"))
    (setq oncol on)
    (start_image "blinkon")
    (fill_image 0 0 onwid onhgt oncol)
    (end_image) ; End Blink ON
    (setq offwid (dimx_tile "blinkoff")) ; Begin Blink OFF
    (setq offhgt (dimx_tile "blinkoff"))
    (setq offcol off)
    (start_image "blinkoff")
    (fill_image 0 0 offwid offhgt offcol)
    (end_image) ; End Blink OFF

  )
;;; End defun
;;;
  (defun save_ini (/ hlini) ; Saves Confinguration to INI file
    (if (findfile (strcat path "HL.ini")) ; Begin if
      (progn ; Begin progn
(princ "\nSaving Configuration...Please Wait. ")
(wait 0.5)
(setq hlini (open (strcat path "hl.ini") "w"))
(write-line
  "Configuration File for Highlight Layer Lisp"
  hlini
)
(write-line "Highlight Layer v1.1  " hlini)
(write-line "\nBlink On" hlini)
(write-line (rtos on 2 0) hlini)
(write-line "Blink Off" hlini)
(write-line (rtos off 2 0) hlini)
(write-line "Blink Speed" hlini)
(write-line (rtos blink 2 2) hlini)
(close hlini)
      ) ; End progn
    ) ; End if

  )
;;; End defun
;;;
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  ;(command "_undo" "BE")
  (vla-startundomark doc)
  (setq old_cmdecho (getvar "cmdecho"))
  (setq old_layer (getvar "clayer"))
  (setq old_regenmode (getvar "regenmode"))
  (setq old_uscicon (getvar "ucsicon"))
  (setvar "cmdecho" 0)
  (setvar "regenmode" 0)
  (setvar "ucsicon" 0)
  (setq path "C:/Base Maps/Jeffs Test Files/Test Lisp/")
  ;;<-------CHANGE THIS HARD CODED PATH
  (setq
    obj (car
  (entsel "\nPick layer to HIGHLIGHT or [ENTER] for Options: "
  )
)
  )
  (if (findfile (strcat path "HL.ini")) ; Begin if
    (progn ; Retrieves information from INI
; file
      (princ "\nRetrieving Configuration...Please Wait. ")
      (wait 0.5)
      (setq hlini (open (strcat path "HL.ini") "r"))
      (read-line hlini)
      (setq version (read-line hlini))
      (read-line hlini)
      (read-line hlini)
      (setq on (atoi (read-line hlini)))
      (read-line hlini)
      (setq off (atoi (read-line hlini)))
      (read-line hlini)
      (setq blink (atof (read-line hlini)))
      (close hlini)
    ) ; End progn
    (progn ; Creates INI file
      (princ "\nCreating Config file...Please Wait. ")
      (wait 0.5)
      (setq hlini (open (strcat path "HL.ini") "w"))
      (write-line
"Configuration File for Highlight Layer Lisp"
hlini
      )
      (write-line "Highlight Layer v1.1  " hlini)
      (write-line "\nBlink On" hlini)
      (write-line "7" hlini)
      (write-line "Blink Off" hlini)
      (write-line "250" hlini)
      (write-line "Blink Speed" hlini)
      (write-line "0.5" hlini)
      (close hlini)
      (setq on 7)
      (setq off 250)
      (setq blink 0.5)
      (setq version "Highlight Layer v1.1  ")
    ) ; End progn
  ) ; End if
  (pick)
  (princ)
)
;;; End defun

;;; End defun
;;;
;;; Echos to the command line
(princ
  "\nHighlight Layer v1.1 \n(c)Timothy Spangler, \nSeptember, 2001....loaded."
)
;;; End echo

GDF

  • Water Moccasin
  • Posts: 2081
Re: Error handler help needed
« Reply #12 on: August 10, 2006, 10:35:03 AM »
Tim and Jeff

That is pretty slick. I have one similar to it that I can now clean up.
Tim thanks for sharing it.

My code that needs to be cleaned up.
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; View Layer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun VIEWLAYIT  (/ tmp)
  (initget "F V")
  (setq tmp (getkword "\n* Select View type:  <F>lash   <V>iewlay *"))
  (cond ((or (= tmp "V") (= tmp nil)) (VIEWLAYSIT))
        ((= tmp "F") (LAYFLASHITX)))
  (princ))
;;;
(defun VIEWLAYSIT  (/ dcl_id ll x no)
  (setq dcl_id (load_dialog (strcat ARCH#LAYF "ARCH_LAYS.DCL")))
  (defun ALERT1  (MSG)
    (new_dialog "alert1" dcl_id "0" (list 400 750))
    (set_tile "set-title" (strcat ARCH#LOGO " : Layer Checking Dialog"))
    (set_tile "alert1" MSG)
    (action_tile "accept" "(done_dialog 1)")
    (action_tile "cancel" "(exit)")
    (start_dialog)
    (princ))
  (defun LAYL  ()
    (setq LL NIL
          LL (list (cdr (assoc 2 (tblnext "LAYER" t))))
          X  (tblnext "LAYER"))
    (while (/= NIL X)
      (setq LL (append LL (list (cdr (assoc 2 X))))
            X  (tblnext "LAYER")))
    LL)
  (setq NO 1
        LL (LAYL))
  (ALERT1
    (strcat "Their are " (itoa (length LL)) " Layer(s) in this Drawing."))
  (setvar "CLAYER" "0")
  (command "zoom" "e")
  (command "layer" "off" "*" "" "")
  (repeat (1- (length LL))
    (progn (command "layer" "on" (nth NO LL) "")
           (ALERT1 (strcat "Displayed Layer : " (nth NO LL)))
           (command "Layer" "off" (nth NO LL) "")
           (setq NO (1+ NO))))
  (command "LAYER" "ON" "0" "")
  (ALERT1 (strcat "Displayed Layer : 0  <Viewing Completed>"))
  (command "LAYER" "ON" "*" "")
  (command "zoom" "p"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun LAYFLASHITX  (/ LAYLST)
  (vl-load-com) 
  (setq LAYOBJ (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
               ;;MATCH   (strcase (getstring "\n* Enter Layer match string: *"))
        )
  (setq MATCH
         (cdr
           (assoc 8
                  (entget
                    (car (entsel "\n* Select an Layer to Flash: <escape to cancel> *"))))))
  (repeat 10000
    (vlax-for
           FOR-ITEM  LAYOBJ
      (if (wcmatch (strcase (vla-get-name FOR-ITEM)) MATCH)
        (progn (vla-put-layeron FOR-ITEM :vlax-true))))
    (repeat 5000 (princ))
    (vlax-for
           FOR-ITEM  LAYOBJ
      (if (wcmatch (strcase (vla-get-name FOR-ITEM)) MATCH)
        (vla-put-layeron FOR-ITEM :vlax-false)))
    (repeat 5000 (princ))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

//////////////////////////////////////////////////////////////////////////////////
//VIEWLAY
alert1 : dialog {key="set-title"; initial_focus="accept";   
  :boxed_column {children_fixed_width=true; children_fixed_height=true;
    :row {
      :button {label=">>"; key="accept"; is_default=true;}
      :spacer {}
      :text_part {key="alert1"; alignment=centered; width=40; height=1.25; fixed_width_font=true;}   
      :button {label="X"; key="cancel"; is_default=true;}
    }
    :spacer {}
  }     
}

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #13 on: August 10, 2006, 11:07:55 AM »
Good stuff you guys.

Additional food for thought.

Sorry for the aberrant brevity / wish I could play in this thread, but duty calls.

:)

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #14 on: August 10, 2006, 11:18:05 AM »
'kay,managed about 2 minutes on this so bear with me. Consider the implications of this little demo (no time to spell it out) --

Code: [Select]
(defun c:Demo ( / ini end foo main )

    (defun ini ( )
        (princ "Intializing ...\n")
    )

    (defun end ( )
        (princ "Terminating ...\n")
        (princ)
    )

    (defun foo ( / result )
        (vl-catch-all-apply
           '(lambda ( )
                (vl-some '(lambda (x) (setq result x))
                    (list
                        (getint
                            (strcat
                                "Enter an integer value, "
                                "[Enter] for the default <42>, "
                                "or <[Esc] to bail: "
                            )   
                        )
                        42
                    )
                )
            )
        )
        result
    )

    (defun main ( / num )
   
        (ini)
       
        (cond
            (   (setq num (foo))
                (princ
                    (strcat
                        "Let's roll with "
                        (itoa num)
                        " ...\n"
                    )
                )
                ;;  do other stuff ...
            )
            (   t
                (princ
                    (strcat
                        "Ok, uncle, user "
                        "doesn't want to play.\n"
                    )
                )
            )
        )
       
        (end)
       
    )

    (main)

)

Bye!

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Error handler help needed
« Reply #15 on: August 10, 2006, 01:04:09 PM »
'kay,managed about 2 minutes on this so bear with me. Consider the implications of this little demo (no time to spell it out) --
Funny, it took less than 2 minutes for this to make my head hurt... :| I'll have to look this over to decipher it when I don't have real work to accomplish.....thanks Michael, it will give me something to do while my wife is driving on our trip to Oregon tomorrow.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #16 on: August 11, 2006, 01:04:43 PM »
Quick bash, may have errors ...

Code: [Select]
(defun c:Demo ( / _SetVars _Initializer _Terminator *error* _Main )

    (defun _SetVars ( lst )
        (mapcar
           '(lambda ( name value )
                (list
                    name
                    (getvar name)
                    value
                    (null
                        (vl-catch-all-error-p
                            (vl-catch-all-apply
                               '(lambda ( ) (setvar name value))
                            )
                        )
                    )
                )   
            )
            (mapcar 'car lst)
            (mapcar 'cadr lst)
        )
    )

    (defun _Initializer ( document / undoIsEnabled oldSysVars )
        ;;  variable *debug* is a lexical global
        (if *debug* (princ "Entering Initializer ... "))
        (cond
            (   (setq undoIsEnabled (< 0 (getvar "undoctl")))
                (while (eq 8 (logand 8 (getvar "undoctl")))
                    (vla-endundomark document)
                )
                (vla-startundomark document)
            )   
        )
        (setq oldSysVars
            (_SetVars
               '(   
                    ("cmdecho"   0)
                    ("regenmode" 1)
                    ("attreq"    0)
                    ;;  yada
                )
            )
        )
        (cond
            (   *debug*
                (if undoIsEnabled (princ "<Undo Started> ... "))
                (princ "Exiting Initializer\n")
            )
        )   
        ;;  return to caller
        (list
            (list 'document document)
            (list 'undoIsEnabled undoIsEnabled)
            (list 'oldSysVars oldSysVars)
        )
    )
   
    (defun _Terminator ( data / document undoIsEnabled oldSysVars )
        ;;  variable *debug* is a lexical global
        (if *debug* (princ "Entering Terminator ... "))
        (foreach arg '(document undoIsEnabled oldSysVars)
            (set arg (cadr (assoc arg data)))
        )
        (if (and undoIsEnabled document) (vla-endundomark document))
        (if oldSysVars (_SetVars oldSysVars))
        (cond
            (   *debug*
                (if (and undoIsEnabled document) (princ "<Undo Ended> ... "))
                (princ "Exiting Terminator\n")
            )   
        )
        (princ)
    )
   
    (defun *error* ( msg )
        (princ "*Abnormal program termination*\n")
        (if *debug* (vl-bt))
        ;;  variable terminatorData is a lexical global 
        (_Terminator terminatorData)
    )
   
    (defun _Main ( / terminatorData *debug* )
        (initget "Yes No")
        (if (eq "Yes" (getkword "Enable debug <verbose> mode? <No>: "))
            (setq *debug* t)
        )
        (setq terminatorData
            (_Initializer
                (vla-get-activedocument
                    (vlax-get-acad-object)
                )
            )
        )
        (initget "Yes No")
        (if (/= "No" (getkword "Do you want to crash me? <Yes>: "))
            (/ 1 0) ;; divide by zero error
        )
        (princ "*Normal program termination*\n")
        (_Terminator terminatorData)
    )
   
    (_Main)
   
)
   

DEMO [Enter]
Enable debug <verbose> mode? <No>: No
Do you want to crash me? <Yes>: No
*Normal program termination*

DEMO [Enter]
Enable debug <verbose> mode? <No>: No
Do you want to crash me? <Yes>: Yes
*Abnormal program termination*

DEMO [Enter]
Enable debug <verbose> mode? <No>: Yes
Entering Initializer ... <Undo Started> ... Exiting Initializer
Do you want to crash me? <Yes>: No
*Normal program termination*
Entering Terminator ... <Undo Ended> ... Exiting Terminator

DEMO [Enter]
Enable debug <verbose> mode? <No>: Yes
Entering Initializer ... <Undo Started> ... Exiting Initializer
Do you want to crash me? <Yes>: Yes
*Abnormal program termination*
Backtrace:
[0.52] (VL-BT)
[1.48] (*ERROR* "divide by zero")
[2.43] (_call-err-hook #<SUBR @0cfd7654 *ERROR*> "divide by zero")
[3.37] (sys-error "divide by zero") :ERROR-BREAK.32 nil
[4.29] (/ 1 0)
[5.23] (_MAIN)
[6.19] (C:DEMO)
[7.15] (#<SUBR @0cfd7dac -rts_top->)
[8.12] (#<SUBR @0d0f2334 veval-str-body> "(C:DEMO)" T #<FILE internal>) ...

Entering Terminator ... <Undo Ended> ... Exiting Terminator
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #17 on: August 11, 2006, 03:00:31 PM »
I've changed my mind about the setvars function, though I'll leave existing posts as is.

I think error trapping the individual setvar calls is a bad idea. I started to think about that approach as applies to my "real world" programming and I could not think of a single instance where I would want to mask a setvar error, that is, prevent a program from crashing. The simple reason being (for me) that a failed setvar call represents a design flaw in my program (either the variable name is wrong or the candidate value is invalid) so I'd actually want it to trash the program (so I could code it proper). As a result I would alter the setvars function to act accordingly --

Code: [Select]
(defun setvars ( lst )
    (mapcar
       '(lambda ( var val ) (list var (getvar var) (setvar var val)))
        (mapcar 'car lst)
        (mapcar 'cadr lst)
    )
)

Argument lst is (still) of the form '(("var" val)("var" val)), for example '(("cmdecho" 0)("regenmode" 1)).

The result is of the form form '(("var" oldval newval), for example '(("cmdecho" 1 0)("regenmode" 0 1)) so it can still be passed to the setvars function later, say at the end of program execution.

I realize this thread has become a ghost town <not sure how I killed it, tmi?> and I'm talking to myself but that's ok, point is still valid.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Error handler help needed
« Reply #18 on: August 11, 2006, 03:07:22 PM »
I realize this thread has become a ghost town <not sure how I killed it, tmi?> and I'm talking to myself but that's ok, point is still valid.
I'm still reading it.  I have just devoted more time to 'try' and learn C#, so I'm not posting as much when I see others have taken, or are going to take, care of someone.  I was just watching to see where you were going, and I was hoping it was here, as that is what I think is the best way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Error handler help needed
« Reply #19 on: August 12, 2006, 11:17:18 AM »
I realize this thread has become a ghost town <not sure how I killed it, tmi?> and I'm talking to myself but that's ok, point is still valid.

I'm still reading it.  I have just devoted more time to 'try' and learn C#, so I'm not posting as much when I see others have taken, or are going to take, care of someone.  I was just watching to see where you were going, and I was hoping it was here, as that is what I think is the best way.

Thanks Tim, appreciated (on both counts).

PS: TMI meant "too much info", not a typo for Tim (in the remote chance that's the way you interpretted it).

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst