Author Topic: routine runs after hitting cancel in dialog  (Read 1527 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
routine runs after hitting cancel in dialog
« on: July 27, 2021, 06:43:52 PM »
The code runs if I hit Cancel or OK.

Can't for the life of me see the error of my ways.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:STA_Scale_TB ( / blk1 siz names dimsc dsty dstydata userclick x obj obj1 obj2 olay ss ss1 ss2 tagname tagname1 tagname2 att att1 att2)
  2.  (defun *error* (msg)
  3.     (if s
  4.       (vla-delete s)
  5.     )
  6.     (if acDoc
  7.       (vla-endundomark acDoc)
  8.     )
  9.     (cond ((not msg))                                                   ; Normal exit
  10.           ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
  11.           ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
  12.     )
  13.     (princ)
  14.   )
  15.  
  16.   (setq SIZ "0")                                        
  17.   (setq NAMES '("NONE" "1/4\" = 1'-0\"" "1/2\" = 1'-0\"" "1\" = 1'-0\"" "1-1/2\" = 1'-0\"" "3\" = 1'-0\"" "6\" = 1'-0\""))
  18.  
  19.   (setq dcl_id (load_dialog "STA_Scale_TB.dcl"))        ;load dialog
  20.  
  21.   (if (not (new_dialog "STA_Scale_TB" dcl_id))          ;test for dialog                                                       
  22.   (exit)                                              ;exit if no dialog
  23.    )                                                    ;if
  24.  
  25.   (start_list "scales")                             ;start the list box
  26.   (mapcar 'add_list NAMES)                              ;fill the list box
  27.   (end_list)                                            ;end list
  28.  
  29.     "cancel"                                            ;if cancel button pressed
  30.     "(done_dialog) (setq userclick nil)"                ;close dialog, set flag
  31.     )                                                   ;action_tile
  32.  
  33.     "accept"                                            ;if O.K. pressed
  34.     (strcat                                             ;string 'em together
  35.       "(progn
  36.         (setq SIZ (get_tile \"scales\")))"      ;get list selection
  37.       " (done_dialog)(setq userclick T))"               ;close dialog, set flag
  38.     )                                                   ;strcat
  39.   )                                                     ;action tile
  40.  
  41.   (start_dialog)                                        ;start dialog
  42.  
  43.   (unload_dialog dcl_id)                                ;unload
  44.  
  45.    (if userclick                                        ;check O.K. was selected
  46.      (progn
  47.        (cond
  48.         ((= SIZ "0") (setvar "dimscale" 1));;FULL
  49.         ((= SIZ "1") (setvar "dimscale" 48));;1/4"
  50.         ((= SIZ "2") (setvar "dimscale" 24));;1/2"
  51.         ((= SIZ "3") (setvar "dimscale" 12));;1"
  52.         ((= SIZ "4") (setvar "dimscale" 8));;1 1/2"
  53.         ((= SIZ "5") (setvar "dimscale" 4));;3"
  54.         ((= SIZ "6") (setvar "dimscale" 2));;6"
  55.        )                                                ;cond
  56.      )                                                  ;progn
  57.    )                                                    ;;if
  58.  
  59. (setq tagname "DRAWINGSCALE")
  60. (setq ss (ssget "x" '((2 . "TBLK_ATT_CTL")(66 . 1))))
  61. (repeat (setq x (sslength ss))
  62. (setq obj (vlax-ename->vla-object (ssname SS (setq x (- x 1) ))))
  63. (if  (= (vla-get-hasattributes obj) :vlax-true)
  64. (foreach att (vlax-invoke obj 'getattributes)
  65. (if (= tagname (strcase (vla-get-tagstring att)))
  66. (vla-put-textstring att (nth (atoi siz) names))
  67. )
  68. )
  69. )
  70. )
  71.  
  72. (setq tagname1 "DESIGNER")
  73. (setq ss1 (ssget "x" '((2 . "TBLK_ATT_CTL")(66 . 1))))
  74. (repeat (setq x (sslength ss1))
  75. (setq obj1 (vlax-ename->vla-object (ssname ss1 (setq x (- x 1) ))))
  76. (if  (= (vla-get-hasattributes obj) :vlax-true)
  77. (foreach att1 (vlax-invoke obj1 'getattributes)
  78. (if (= tagname1 (strcase (vla-get-tagstring att1)))
  79. (vla-put-textstring att1 (substr (getvar "loginname") 1 3))
  80. )
  81. )
  82. )
  83. )
  84.  
  85.   (setq dimsc (getvar 'dimscale))
  86.   (command "-layer" "unlock" "TBLK_BORD_LINES" "")
  87.  
  88.   (if (setq blk1 (ssget "x" '((2 . "TBLK_BORD_CTL,TBLK_ATT_CTL"))))
  89.         (command "scale" blk1 "" "0,0" dimsc)
  90.   )
  91.   (command "-layer" "lock" "TBLK_BORD_LINES" "")
  92.  
  93.  
  94.   (if (= (tblsearch "Layer" "TBLK_TBLK_REVINIT"))
  95.   (command "-Layer" "Make" "TBLK_TBLK_REVINIT" "c" "green" "TBLK_TBLK_REVINIT" "")
  96.   )
  97.  
  98.    (setvar 'dynmode 0)
  99.    (while (setq dsty (tblnext "dimstyle" (not dsty)))
  100.    (setq dstydata (entget (tblobjname "dimstyle" (cdr (assoc 2 dsty)))))
  101.    (if (assoc 40 dstydata)                                                      ; [because not included in data if default 1.0]
  102.        (entmod (subst (cons 40 dimsc) (assoc 40 dstydata) dstydata))            ; then -- replace it
  103.        (entmod (append dstydata (list (cons 40 dimsc))))                        ; else -- add it
  104.     )
  105.   )
  106.  
  107.         (command "._insert" "Note_Rev_NewDwg_ATT" "0,0" dimsc dimsc "")
  108.         (command "._explode" "last")
  109.         (command "-layer" "Filter" "Set" "Stations Standard Layers" "exit" "")
  110.         (command "layer" "M" "LINE1" "C" "YELLOW" "LINE1" "")
  111.         (command "zoom" "e")
  112.         (command "limits" (getvar "extmin") (getvar "extmax"))
  113.  
  114.         (setvar "CMDECHO" 0)
  115.         (setvar "BLIPMODE" 0)
  116.  
  117.         (command ".style" "Standard" "ipco.shx" (* 1.000 dimsc) "0.85" "0" "n" "n" "n")
  118.         (command ".style" "L080" "ipco.shx" (* 0.0781 dimsc) "0.85" "0" "n" "n" "n")
  119.         (command ".style" "L100" "ipco.shx" (* 0.0938 dimsc) "0.85" "0" "n" "n" "n")
  120.         (command ".style" "L120" "ipco.shx" (* 0.1094 dimsc) "0.85" "0" "n" "n" "n")
  121.         (command ".style" "L140" "ipco.shx" (* 0.1406 dimsc) "0.85" "0" "n" "n" "n")
  122.         (command ".style" "L175" "ipco.shx" (* 0.1563 dimsc) "0.85" "0" "n" "n" "n")
  123.         (command ".style" "L200" "ipco.shx" (* 0.1719 dimsc) "0.85" "0" "n" "n" "n")
  124.         (command ".style" "L240" "ipco.shx" (* 0.2187 dimsc) "0.85" "0" "n" "n" "n")
  125.         (command ".style" "Ls080" "ipco.shx" (* 0.0781 dimsc) "0.85" "20" "n" "n" "n")
  126.         (command ".style" "Ls100" "ipco.shx" (* 0.0938 dimsc) "0.85" "20" "n" "n" "n")
  127.         (command ".style" "Ls120" "ipco.shx" (* 0.1094 dimsc) "0.85" "20" "n" "n" "n")
  128.         (command ".style" "Ls140" "ipco.shx" (* 0.1406 dimsc) "0.85" "20" "n" "n" "n")
  129.         (command ".style" "Ls175" "ipco.shx" (* 0.1563 dimsc) "0.85" "20" "n" "n" "n")
  130.         (command ".style" "Ls200" "ipco.shx" (* 0.1719 dimsc) "0.85" "20" "n" "n" "n")
  131.         (command ".style" "Ls240" "ipco.shx" (* 0.2187 dimsc) "0.85" "20" "n" "n" "n")
  132.         (command ".style" "PEN0" "ipco.shx" (* 0.0625 dimsc) "0.85" "0" "n" "n" "n")
  133.         (command ".style" "PEN1" "ipco.shx" (* 0.0781 dimsc) "0.85" "0" "n" "n" "n")
  134.         (command ".style" "PEN2" "ipco.shx" (* 0.1250 dimsc) "0.85" "0" "n" "n" "n")
  135.         (command ".style" "PEN2s" "ipco.shx" (* 0.1000 dimsc) "0.85" "0" "n" "n" "n")
  136.         (command ".style" "PEN3" "ipco.shx" (* 0.1875 dimsc) "0.85" "0" "n" "n" "n")
  137.         (command ".style" "PEN4" "ipco.shx" (* 0.2500 dimsc) "0.85" "0" "n" "n" "n")
  138.         (command ".style" "PEN5" "ipco.shx" (* 0.3125 dimsc) "0.85" "0" "n" "n" "n")
  139.  
  140.         (setvar "cmdecho" 1)
  141.  
  142.  
  143. )
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: routine runs after hitting cancel in dialog
« Reply #1 on: July 27, 2021, 11:29:59 PM »
Your end of (if userclick   is only a few lines down so rest of code will run, maybe  use a simple hard exit out. I did not look to closely at what is to run and whats not. You could call a defun as part of the exit resetting variables etc 1st then exit. The other way is move ) ; progn ) ; if further down

(if (= userclick   nil)(progn (alert "now exiting ")(exit)))
A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 327
Re: routine runs after hitting cancel in dialog
« Reply #2 on: July 28, 2021, 11:49:47 AM »
Your end of (if userclick   is only a few lines down so rest of code will run, maybe  use a simple hard exit out. I did not look to closely at what is to run and whats not. You could call a defun as part of the exit resetting variables etc 1st then exit. The other way is move ) ; progn ) ; if further down

(if (= userclick   nil)(progn (alert "now exiting ")(exit)))

I thought I already tried the moving the ) ; progn ) ; already. Gave it another go and all is well. I may have moved the ); cond with it.

As for your defun suggestion:

Code - Auto/Visual Lisp: [Select]
  1. (defun *error* (msg)
  2.     (if osm
  3.       (setvar 'osmode osm)
  4.     )
  5.  
  6.     (if (= userclick   nil)(progn (alert "now exiting ")(exit)));;;put BIGALs suggestion here ??????
  7.  
  8.     (if (not (member msg '("Function cancelled" "quit / exit abort")))
  9.       (princ (strcat "\nError: " msg))
  10.     )
  11.    
  12.     (princ)
  13.   )

Is this what you're suggesting?

J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: routine runs after hitting cancel in dialog
« Reply #3 on: July 28, 2021, 12:07:00 PM »
I recommend spending some time picking a good formatting (indentation) for your code to help yourself READ code faster. Below is a link to a quick write-up (introduction) I did for a series of tutorials I was doing at one point.

https://www.theswamp.org/index.php?topic=55692.msg598047#msg598047
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

jlogan02

  • Bull Frog
  • Posts: 327
Re: routine runs after hitting cancel in dialog
« Reply #4 on: July 28, 2021, 12:10:05 PM »
Thanks. I've been looking for this. Or something like this. Just snagged Lee's Lisp styler. Not to be confused with a lips styler :)
« Last Edit: July 28, 2021, 12:14:18 PM by jlogan02 »
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: routine runs after hitting cancel in dialog
« Reply #5 on: July 28, 2021, 01:02:04 PM »
Thanks. I've been looking for this. Or something like this. Just snagged Lee's Lisp styler. Not to be confused with a lips styler :)

Glad I could (possibly) help.

I just looked up Lee's lisp styler; please do not use that here on TheSwamp. You can certainly use the plain BBCODE (CODE) to display your code but we have a custom code tag system we developed for our developers(users) to display their code with built in help for the AutoLisp language. ...You must already know this, but I just wanted to note that for other people reading this post.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

jlogan02

  • Bull Frog
  • Posts: 327
Re: routine runs after hitting cancel in dialog
« Reply #6 on: July 28, 2021, 02:37:29 PM »
Thanks. I've been looking for this. Or something like this. Just snagged Lee's Lisp styler. Not to be confused with a lips styler :)

Glad I could (possibly) help.

I just looked up Lee's lisp styler; please do not use that here on TheSwamp. You can certainly use the plain BBCODE (CODE) to display your code but we have a custom code tag system we developed for our developers(users) to display their code with built in help for the AutoLisp language. ...You must already know this, but I just wanted to note that for other people reading this post.

Very good info. Thanks
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: routine runs after hitting cancel in dialog
« Reply #7 on: July 29, 2021, 12:40:26 AM »
Bricscad Blade has a Beautify option. The only issue was uses tabs so a copy and paste direct to command line does some odd things some times.

The exit  defun would be in you core code not in the error code that is different again. (exit) is hit it with a big hammer.
A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 327
Re: routine runs after hitting cancel in dialog
« Reply #8 on: July 29, 2021, 12:31:46 PM »
Got it. Thanks
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10