Author Topic: Append a list to existing list of a list box  (Read 1613 times)

0 Members and 1 Guest are viewing this topic.

Giuseppe Beatrice

  • Newt
  • Posts: 43
Append a list to existing list of a list box
« on: July 20, 2016, 05:44:53 AM »
I have a problem with a list_box DCL.
The instruction (start_list "..." 2) should add a new list entry to a list inserted in a list box, as I have understood by the online Visual lisp guide.
Well, why does not this happen?
If I have a list of strings inserted in a list box and then I want to add a new list I have written the below instruction set:
(start_list "klbox2" 2)
(mapcar 'add_list lst2@)
(end_list)

But the result is the new list substituted to the existing list and not the awaited append action, the same result that I get with the instruction set:
(start_list "klbox2" 3)
(mapcar 'add_list lst2@)
(end_list)

Is there anyone who can explain me where is the error?
Thanks in advance.
« Last Edit: July 20, 2016, 05:49:12 AM by Giuseppe Beatrice »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Append a list to existing list of a list box
« Reply #1 on: July 20, 2016, 06:07:58 AM »
IMO your code should work. Maybe some other part of your code is to blame? E.g. (set_tile "klbox2" "") somewhere?

Giuseppe Beatrice

  • Newt
  • Posts: 43
Re: Append a list to existing list of a list box
« Reply #2 on: July 20, 2016, 10:39:37 AM »
This is my example of list_box DCL file, with an initial list-box of two layers, and I want to add to that list the layer of a line selected from the drawing.
Initial list-box is formed with the list defined in row 15 and written in the dialog box by rows from 21 to 23.
Then action on the button should rewrite the list with the layer name of the line selected and add it  to list-box with the same actions in rows 21-23, but it doesn't...
Code - Auto/Visual Lisp: [Select]
  1. [(defun INS_EL_DCL  (/ addlst@ flag cnt1 lblbut@@ lbllbox@ but&lstbox@@ des fname dcl_id return# lst1@ value2$)
  2.   (setq cnt1 0)
  3.   (setq lblbut@@ '(("ADD LAYER")))
  4.   (setq lbllbox@ '("TREE BRANCH LAYERS"))
  5.   (setq but&lstbox@@
  6.          (mapcar '(lambda (but@ lbllbox$)
  7.                     (setq cnt1 (1+ cnt1)
  8.                           cnt2 0)
  9.                     (cons (cons (strcat "klbox" (itoa cnt1)) lbllbox$)
  10.                           (mapcar '(lambda (but$) (setq cnt2 (1+ cnt2)) (cons (strcat "but_" (itoa cnt1) (itoa cnt2)) but$))
  11.                                   but@)))
  12.                  lblbut@@
  13.                  lbllbox@))
  14.   (setq flag 2)
  15.   (setq lst1@ '("Layer 1" "Layer 2"))
  16.   (CRDLG_LYR&PT-ALBERO tytle but&lstbox@@)
  17.   (while (> flag 1)
  18.     (if (not (new_dialog "temp" dcl_id))
  19.       (exit))
  20.     (set_tile "Title" "TREE ELEMENT INSERTION")
  21.     (start_list "klbox1" 2)
  22.     (mapcar 'add_list lst1@)
  23.     (end_list)
  24.     (action_tile "but_11" "(done_dialog 3) ")
  25.     (action_tile "cancel" "(done_dialog 0)")
  26.     (action_tile "accept" "(done_dialog 1)")
  27.     (setq flag (start_dialog))
  28.     (cond ((= flag 3) (setq lst1@ (list (cdr (assoc 8 (entget (car (entsel "get a line of the tree"))))))))
  29.           ((= flag 1) (alert "Tasto OK"))
  30.           ((= flag 0) (alert "Program interrupted by user") (exit))))
  31.   (unload_dialog dcl_id)
  32.   (vl-file-delete fname))
  33.  
  34. ;;;---------------------------------------------------------------------------------------------------------------------------------------------------
  35. (defun CRDLG_LYR&PT-ALBERO  (tytle but&lstbox@@ / istr@ )
  36.   (setq fname (vl-filename-mktemp "temp.dcl"))
  37.   (setq des (open fname "w"))
  38.   (setq istr@ (LM:flatten(append (DCL_DEFLSTBOX 30 20 T T T)
  39.                       (DCL_DEFBUTTON 6.0 2.5 T T)
  40.                       (list (strcat "temp : dialog {key = \"Title\";  label = \"\"; " ))
  41.                       '(" : row {")
  42.                       (mapcar '(lambda (x!)
  43.                                  (list " : column { " (DCL_LSTBOX (car x!)) " : row {" (DCL_BUTTON (cdr x!)) " }}"))
  44.                               but&lstbox@@)
  45.                       '("}")
  46.                       (list " : row {" (DCL_OK&CANCEL) "}")
  47.                       '("}"))))
  48.   (mapcar '(lambda (x$) (write-line x$ des)) istr@)
  49.   (setq des (close des))
  50.   (setq dcl_id (load_dialog fname)))
  51.  
  52. ;;;---------------------------------------------------------------------------------------------------------------------------------------------------
  53. (defun DCL_DEFLSTBOX  (w# h# fixw fixh msel)
  54.   (mapcar '(lambda (x)
  55.              (if (eval x)
  56.                (set x "true")
  57.                (set x "false")))
  58.           '(fixw fixh msel))
  59.   (list
  60.     (strcat (strcat "lst : list_box {width = " (itoa w#) "; " "height = " (itoa h#) "; ")
  61.             (strcat "fixed_width = " fixw "; " "fixed_height = " fixh "; " "alignment = centered; ")
  62.             (strcat "multiple_select = " msel "; " "}"))));_ lista restituita a funzione chiamante
  63.  
  64. (defun DCL_DEFBUTTON  (w# h# fixw fixh)
  65.   (mapcar '(lambda (x)
  66.              (if (eval x)
  67.                (set x "true")
  68.                (set x "false")))
  69.           '(fixw fixh))
  70.   (list
  71.     (strcat (strcat "but : button {width = " (rtos w#) "; " "height = " (rtos h#) "; ")
  72.             (strcat "fixed_width = " fixw "; " "fixed_height = " fixh "; " "alignment = centered; " "}"))))
  73.  
  74. (defun DCL_BUTTON  (k&lbl!@)
  75.   (mapcar '(lambda (k&lbl!) (strcat ": but {key = \"" (car k&lbl!) "\" ; " "label = \"" (cdr k&lbl!) "\" ;}"))
  76.           k&lbl!@))      
  77.  
  78. (defun DCL_LSTBOX  (k&lbl! / k$ lbl$)
  79.   (setq k$   (car k&lbl!)
  80.         lbl$ (cdr k&lbl!))
  81.   (list (strcat ": lst {key = \"" k$ "\" ; " "label = \"" lbl$ "\" ;}")))
  82.  
  83. (defun DCL_OK&CANCEL (/) '("spacer ; ok_cancel ; alignment = centered; "))
  84.  
  85. ;; Flatten List  -  Lee Mac
  86. ;; Transforms a nested list into a non-nested list
  87. (defun LM:flatten  (l)
  88.   (if (atom l)
  89.     (list l)
  90.     (append (LM:flatten (car l))
  91.             (if (cdr l)
  92.               (LM:flatten (cdr l))))))]
« Last Edit: July 20, 2016, 10:51:02 AM by Giuseppe Beatrice »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Append a list to existing list of a list box
« Reply #3 on: July 20, 2016, 12:07:39 PM »
You have misunderstood the functionality of start_list. (start_list "tile" 2) etc. will add to a list tile in an *active* dialog. In your code you dismiss the dialog inside a while loop. Before you (re)display the dialog with (start_dialog) you have to fill the list tile from scratch. Keep in mind that DCL dialogs are modal dialogs. They can be dismissed but not hidden.

Your problem can quite simply be solved by appending new items to the lst1@ list.

BTW: To improve your code you should check what happens if 'the user' does not select an entity.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Append a list to existing list of a list box
« Reply #4 on: July 20, 2016, 12:10:39 PM »
Code: [Select]
(setq lst1@ (append lst1@ (list (cdr (assoc 8 (entget (car (entsel "get a line of the tree"))))))))
Keep smile...

Giuseppe Beatrice

  • Newt
  • Posts: 43
Re: Append a list to existing list of a list box
« Reply #5 on: July 21, 2016, 03:36:28 AM »
Thank you Roy; I have substituted the command and it works fine.
Cheers.