Aftertouch Posted November 19 Posted November 19 (edited) Hello all, I want to make a digital 'tree-catalog' for my collegaes. We are building a huge CSV database with information. I want a DCL that has a picklist, and when i select a tree-type from the list, the label shows additional information. The DCL is working, but i got no clue on where to start with the dynamic labels. So when i pick a tree from the picklist, i want label 1 to show colum A, label 2 to show calum B etc. Is this possible? EDIT: added @Lee Mac his CSV function, the lisp uses. ;;--------------------------------------------;; ;;--------------------------------------------;; (defun C:GENEREERBOMEN ( / *error* bomendata boomdata boomsoorten boomafkorting boomgrootte boomdiametermin boomdiametermax) (vl-load-com) (if (not (setq bomendata (LM:readcsv (getfiled "\nSelecteer bestand om te importeren... " "" "csv" 16)))) (prog (alert "Bomencatalogus niet gevonden!") ) (progn (setq bomendata (cdr bomendata)) (setq i 0) (repeat (length bomendata) (setq boomdata (nth i bomendata)) (setq boomsoorten (cons (nth 0 boomdata) boomsoorten)) (setq boomafkorting (cons (nth i boomdata) boomafkorting)) (setq boomgrootte (cons (nth i boomdata) boomgrootte)) (setq boomdiametermin (cons (nth i boomdata) boomdiametermin)) (setq boomdiametermax (cons (nth i boomdata) boomdiametermax)) (setq i (+ 1 i)) ) ;; DCL BOUWEN (setq dcl_content "picklist_dialog : dialog { label = \"Bomencatalogus:\"; : column { ") (setq dcl_contentmiddle "") (setq dcl_contentmiddle (strcat dcl_contentmiddle ": row { : column { : text { label = \"Boomsoorten\"; key = \"Tabellen\"; } : popup_list { key = \"tabellen_list\"; width = 60; popup_list_height = 6; } : text { key = \"dynamic_label\"; label = \"Default Label 1\"; } : text { key = \"dynamic_label_2\"; label = \"Default Label 2\"; } : text { key = \"dynamic_label_3\"; label = \"Default Label 3\"; } : text { key = \"dynamic_label_4\"; label = \"Default Label 4\"; } : text { key = \"dynamic_label_5\"; label = \"Default Label 5\"; } } }")) (setq dcl_content2 "} : spacer {} : row { : button { label = \"OK\"; key = \"accept\"; is_default = true; } : button { label = \"Cancel\"; key = \"cancel\"; } } }") ;; Define the temporary DCL file path (setq dcl_filename (strcat (getvar "TEMPPREFIX") "picklist_temp.dcl")) ;; Create and write the DCL content to the temporary file (setq dcl_id (open dcl_filename "w")) (if dcl_id (progn (write-line (strcat dcl_content dcl_contentmiddle dcl_content2) dcl_id) (close dcl_id) ) (progn (princ "\nError: Unable to create temporary DCL file.") (exit) ) ) ;; Load the temporary DCL file (setq dcl_id (load_dialog dcl_filename)) (if (not (new_dialog "picklist_dialog" dcl_id)) (progn (princ "\nError: Unable to load dialog.") (exit) ) ) ;; Define picklist contents in LISP (setq tabellen_options (reverse boomsoorten)) ;; Load the content of each picklist (start_list "tabellen_list") (mapcar 'add_list tabellen_options) (end_list) ;; Define actions for the dialog (action_tile "accept" "(progn (setq pickresult (nth (atoi (get_tile \"tabellen_list\")) (eval (read \"tabellen_options\")))) (done_dialog 1) )") (action_tile "cancel" "(progn (done_dialog 0) )") ;; Intercept the close button action (X button) (action_tile "close" "(progn (done_dialog 0) )") ;; Start the dialog (start_dialog) ;; Unload the dialog and delete the temporary DCL file (unload_dialog dcl_id) (vl-file-delete dcl_filename) (if (not pickresult) (progn (alert "Geen keuze gemaakt!") ) (progn (alert pickresult) ) ) ) ) (princ) ) (defun LM:readcsv ( csv / des lst sep str ) (if (setq des (open csv "r")) (progn (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (","))) (while (setq str (read-line des)) (setq lst (cons (LM:csv->lst str sep 0) lst)) ) (close des) ) ) (reverse lst) ) (defun LM:csv->lst ( str sep pos / s ) (cond ( (not (setq pos (vl-string-search sep str pos))) (if (wcmatch str "\"*\"") (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2)))) (list str) ) ) ( (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]") (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos))) ) (LM:csv->lst str sep (+ pos 2)) ) ( (wcmatch s "\"*\"") (cons (LM:csv-replacequotes (substr str 2 (- pos 2))) (LM:csv->lst (substr str (+ pos 2)) sep 0) ) ) ( (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0))) ) ) (defun LM:csv-replacequotes ( str / pos ) (setq pos 0) (while (setq pos (vl-string-search "\"\"" str pos)) (setq str (vl-string-subst "\"" "\"\"" str pos) pos (1+ pos) ) ) str ) (defun LM:writecsv ( lst csv / des sep ) (if (setq des (open csv "w")) (progn (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (","))) (foreach row lst (write-line (LM:lst->csv row sep) des)) (close des) t ) ) ) ;; List -> CSV - Lee Mac ;; Concatenates a row of cell values to be written to a CSV file. ;; lst - [lst] list containing row of CSV cell values ;; sep - [str] CSV separator token (defun LM:lst->csv ( lst sep ) (if (cdr lst) (strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep)) (LM:csv-addquotes (car lst) sep) ) ) (defun LM:csv-addquotes ( str sep / pos ) (cond ( (wcmatch str (strcat "*[`" sep "\"]*")) (setq pos 0) (while (setq pos (vl-string-position 34 str pos)) (setq str (vl-string-subst "\"\"" "\"" str pos) pos (+ pos 2) ) ) (strcat "\"" str "\"") ) ( str ) ) ) ;;--------------------------------------------;; ;;--------------------------------------------;; (princ) ;;--------------------------------------------;; ;;--------------------------------------------;; BOMEN.csv Edited November 19 by Aftertouch Quote
pkenewell Posted November 19 Posted November 19 (edited) While I don't completely understand the use/purpose, and I can't get the data correctly because my standard CSV delimiter is different, to get the value from the list box then do something with it, you use (action_tile) and (Set_tile). See the following example for an idea (my apologies I don't understand how the data is structured yet and don't have time to figure it out): ;; The popup list returns the index of the selected item as a string with the $value return variable. convert it to an integer and use it to index your data. (action_tile "tabellen_list" "(setq lret (atoi $value))(set_tile \"dynamic_label\" (nth lret ...))(set-tile \"dynamic_label2\" ...)" ) Edited November 19 by pkenewell 1 Quote
Aftertouch Posted November 19 Author Posted November 19 Hi @pkenewell, what i am looking for, is that the DCL shows the information from the CSV file. So our user can select a 'type of tree' from the list, and instantly sees the information. For example, below the desired result, wich matches the same line of the CSV. When i press 'OK', the data is set the a symbol and i can generate the blocks and layers i want. But this 'preview' is not working as wanted... Somehow, when i pick a value from the list, the 'labels' needs to be updated, without selecting the 'OK' button. Edited the original post to include the CSV functions. Quote
Aftertouch Posted November 19 Author Posted November 19 Solved it, thanks to @pkenewell solution: (action_tile "tabellen_list" "(setq lret (atoi $value)) (set_tile \"dynamic_label\" (nth lret (reverse boomsoorten))) (set_tile \"dynamic_label_2\" (nth lret (reverse boomafkorting))) (set_tile \"dynamic_label_3\" (nth lret (reverse boomgrootte))) (set_tile \"dynamic_label_4\" (nth lret (reverse boomdiametermin))) (set_tile \"dynamic_label_5\" (nth lret (reverse boomdiametermax))) ") 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.