Author Topic: Dialog woes  (Read 1576 times)

0 Members and 1 Guest are viewing this topic.

CincyJeff

  • Newt
  • Posts: 89
Dialog woes
« on: October 13, 2015, 10:27:49 AM »
I'm trying to create a routine that will scan the drawing for blocks on a certain layer that have visibility states. It will then display the name of each block with the current visibility state in a pop-up list. The user will then be able to change the visibility state for each block using the available options in each pop-up list. Since I don't know how many blocks there may be I create the dialog on the fly. I've taken the basic code shown below from Lee Mac's MASK routine. Thanks Lee. The temporary dialog file is created and loads fine. It also allows me to change the pop-up list for each block. However, I cannot get the value of each pop-up list on close. I've even stopped the program before the dialog is unloaded and before the temporary file is deleted and I still cannot use get_tile to retrieve the pop-up list values. If the dialog closes with OK, dlgval will be 1 so the if statement in the code will run to create symbols line1, line2, etc... for each block. The symbol arglst is a list of visibility states for each block, e.g. ((vis1 vis2) (vis1 vis2 vis3) ...). The commented out action_tile code also does not work. Any ideas?

Code - Auto/Visual Lisp: [Select]
  1. (defun DSET:RUNDIALOG (/ cntr dlgid dlgval file filename)
  2.   (cond
  3.     ((null
  4.        (and
  5.          (setq filename (vl-filename-mktemp nil nil ".dcl"))
  6.          (setq file (open filename "w"))
  7.          (progn
  8.            (foreach line
  9.                          (append
  10.                            '(
  11.                              "MainDetailSet : dialog {"
  12.                              "label = \"Detail Set\";"
  13.                             )
  14.                            (DSET:DLGLINES)
  15.                            '("ok_cancel;"
  16.                              "}"
  17.                             )
  18.                          ) ;_ end of append
  19.              (write-line line file)
  20.            ) ;_ end of foreach
  21.            (setq file (close file))
  22.            (< 0 (setq dlgid (load_dialog filename)))
  23.          ) ;_ end of progn
  24.        ) ;_ end of and
  25.      ) ;_ end of null
  26.      (princ "\nUnable to Load Dialog.")
  27.     )
  28.     (t
  29.      (while (not (member dlgval '(0 1)))
  30.        (cond
  31.          ((null (new_dialog "MainDetailSet" dlgid))
  32.           (princ "\nCannot find Detail Set Dialog Definition.")
  33.           (setq dlgval 0)
  34.          )
  35.          (t
  36.           (setq cntr 1)
  37.           (foreach item arglst
  38.             (set (read (strcat "t:lst" (itoa cntr)))
  39.                  (nth (1- cntr) arglst)
  40.             ) ;_ end of set
  41.             (start_list (strcat "t:line" (itoa cntr)) 3)
  42.             (mapcar 'add_list
  43.                     (vl-symbol-value (read (strcat "t:lst" (itoa cntr))))
  44.             ) ;_ end of mapcar
  45.             (end_list)
  46.             (set_tile (strcat "t:line" (itoa cntr))
  47.                       (car (nth (1- cntr) arglst))
  48.             ) ;_ end of set_tile
  49. ;;;            (action_tile
  50. ;;;              (strcat "t:line" (itoa cntr))
  51. ;;;              "(set (read (strcat \"line\" (itoa cntr)))
  52. ;;;                 (get_tile (strcat \"t:line\" (itoa cntr)))
  53. ;;;            )" ;_ end of set
  54. ;;;            ) ;_ end of action_tile
  55.             (setq cntr (1+ cntr))
  56.           ) ;_ end of foreach
  57.           (setq dlgval (start_dialog))
  58.          )
  59.        ) ;_ end of cond
  60.      ) ;_ end of while
  61.     )
  62.   ) ;_ end of cond
  63.   (if (= 1 dlgval)
  64.     (progn
  65.       (setq cntr 1)
  66.       (while (<= cntr (length arglst))
  67.         (set (read (strcat "line" (itoa cntr)))
  68.              (get_tile (strcat "t:line" (itoa cntr)))
  69.         ) ;_ end of set
  70.         (setq cntr (1+ cntr))
  71.       ) ;_ end of while
  72.       (setq dlgid (unload_dialog dlgid))
  73.     ) ;_ end of progn
  74.   ) ;_ end of if
  75.   (if (< 0 dlgid)
  76.     (setq dlgid (unload_dialog dlgid))
  77.   ) ;_ end of if
  78.   (if (and filename (findfile filename))
  79.     (vl-file-delete filename)
  80.   ) ;_ end of if
  81.   (UTIL:RESETDEBUG)
  82. ) ;_ end of defun - DSET:RUNDIALOG
  83.  
  84. (defun DSET:DLGLINES (/ cntr dlgline)
  85.   (setq cntr 1)
  86.   (foreach item blklst
  87.     (setq dlgline (append dlgline
  88.                           (list ": row {"
  89.                                 ": text {"
  90.                                 (strcat "label = \"" (car item) "\";")
  91.                                 "fixed_width = true;"
  92.                                 "width = 50;"
  93.                                 "}"
  94.                                 ": popup_list {"
  95.                                 (strcat "key = \"t:line" (itoa cntr) "\";")
  96.                                 "fixed_width = true;"
  97.                                 "width = 50;"
  98.                                 "}"
  99.                                 "}"
  100.                           ) ;_ end of list
  101.                   ) ;_ end of append
  102.     ) ;_ end of setq
  103.     (setq arglst (append arglst (cddr item)))
  104.     (setq cntr (1+ cntr))
  105.   ) ;_ end of foreach
  106.   dlgline
  107. ) ;_ end of defun - DSET:DLGLINES

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Dialog woes
« Reply #1 on: October 13, 2015, 12:36:11 PM »
You are trying to read values from a dialog that is already closed.
Create an action for the "accept" button that reads and stores the values. I would store them in a list instead of creating lots of unlocalised variable names on the fly.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Dialog woes
« Reply #2 on: October 13, 2015, 12:53:32 PM »
The code you have commented out should be (untested):
Code - Auto/Visual Lisp: [Select]
  1.   (strcat "t:line" (itoa cntr))
  2.   (strcat "(setq line" (itoa cntr) " (get_tile \"t:line" (itoa cntr) "\"))")
  3. )

CincyJeff

  • Newt
  • Posts: 89
Re: Dialog woes
« Reply #3 on: October 13, 2015, 01:46:35 PM »
Thanks roy_043, the action_tile code did the trick. I'll look into the list idea as it does make more sense. Thanks again.