Kvlar Posted April 1 Posted April 1 (edited) I try to created mleader with information based on the contents of the .txt file. The problem is that I can't select one of the dcl list boxes. What happens is that Leader creates all the information based on the .txt file this is the autolisp file that I use : Edited April 5 by Kvlar Quote
BIGAL Posted April 2 Posted April 2 My take on the task. (defun c:test ( / tmp-dcl-file-name dcl_file x fname file line l) (if (setq fname (getfiled "Select txt File" "" "txt" 16)) (progn (setq file (open fname "r") lst '()) (while (setq line (read-line file)) (setq lst (append lst (list line))) ) (close file) (if (not AHlstbox)(load "Listbox-AH.lsp")) (setq ans (nth (ahlstbox "Pick a value" lst 20 10) lst)) (command "_mleader" pause pause ans) ) ) (princ) ) (c:test) Listbox-AH.lsp Quote
Jonathan Handojo Posted April 3 Posted April 3 (edited) I'm only commenting on this based on just looking at your code (and I haven't tried anything yet), but you would need to put an action_tile for "accept" as well, in the event that the user clicks the OK button. As the user clicks the Select button, you need your code to update the list l. So, you would need to put something like: (action_tile "accept" "(setq l (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" (get_tile \"list\") \")\" )))) (done_dialog)") This is completely untested, but you will need to put a line like this before starting your dialog. Edited April 3 by Jonathan Handojo Quote
Kvlar Posted April 3 Author Posted April 3 I think this is the problem. I will try it, thank you 5 hours ago, Jonathan Handojo said: I'm only commenting on this based on just looking at your code (and I haven't tried anything yet), but you would need to put an action_tile for "accept" as well, in the event that the user clicks the OK button. As the user clicks the Select button, you need your code to update the list l. So, you would need to put something like: (action_tile "accept" "(setq l (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" (get_tile \"list\") \")\" )))) (done_dialog)") This is completely untested, but you will need to put a line like this before starting your dialog. I think this is the problem. I will try it, thank you Quote
pkenewell Posted April 3 Posted April 3 On 4/1/2024 at 7:22 PM, Kvlar said: (setq rtn (set_tile "list" "0")) Another problem is there is no tile in the DCL you are writing with the key "list", I see a list box with the key = "select"? Your (set_tile), (get_tile) and (action_tile) call must use a valid key from the DCL file. Quote
Kvlar Posted April 3 Author Posted April 3 14 minutes ago, pkenewell said: Another problem is there is no tile in the DCL you are writing with the key "list", I see a list box with the key = "select"? Your (set_tile), (get_tile) and (action_tile) call must use a valid key from the DCL file. Can you tell me which parts I need to fix? Quote
BIGAL Posted April 3 Posted April 3 (edited) Did you try my code its all you need. It will pop a dcl list box for you to select an item. You may need to change 20 is width 10 is how many lines to display. Edited April 3 by BIGAL Quote
pkenewell Posted April 4 Posted April 4 20 hours ago, Kvlar said: Can you tell me which parts I need to fix? I'll try. I can't test this because your code is not complete and I don't have your text file. Change this: (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") to this: (setq rtn (nth 0 l)) (set_tile "select" "0") (action_tile "select" "(setq rtn (nth (atoi $value) l))") Quote
pkenewell Posted April 4 Posted April 4 (edited) @Kvlar OK - I took a bit of time and went through your whole code, changing it to what it should look like. Please study it with my comments and ask questions if you really want to learn more. EDIT - I added code for Multiple note selection, which I noticed you were trying to do, but it needed adding a parsing function to separate the list into just the selected items. ;; Made this into a function to return the file name of the DCL if written successfully. ;; Localize your variables! (defun Write_DCL (/ dcl_file tmp-dcl-file-name) ;; Set the dcl file name and open it as a ASCII file for writing (setq dcl_file (open (setq tmp-dcl-file-name (vl-filename-mktemp nil nil ".DCL")) "w")) ;; I removed the (progn) as it is not necessary, and I eliminated some invalid ;; DCL stuff from your DCL list. (foreach x '( "Example : dialog {" " label = \"Test Dialog \";" " : column {" " : row {" " : boxed_column {" " : list_box {" " label =\"Select\";" " key = \"select\";" " height = 20;" " width = 40;" " multiple_select = true;" " value = \"\";" " }" " }" " }" " : row {" " : boxed_row {" " : button {" " key = \"accept\";" " label = \" Select \";" " is_default = true;" " }" " : button {" " key = \"cancel\";" " label = \" Cancel \";" " is_default = false;" " is_cancel = true;" " }" " }" " }" " }" "}" ) (write-line x dcl_file) ) ;; Close the DCL file (close dcl_file) ;; Return the DCL file name if the write is good, otherwise NIL (if (findfile tmp-dcl-file-name) tmp-dcl-file-name nil) ); end defun (write_dcl) ;; Function to parse a string into a list at a delimiter (defun StrParse (str del / pos) (if (and str del) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (StrParse (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) );; end defun (StrParse) ;; Localize your variables! (defun c:test (/ fname dclf dcl_ret i l rl rtn x) ;; Load Viaual LISP functions - for (vl-file-delete) (vl-load-com) ; If the TEST.txt file exists AND the Temporary DCL file is written, then (if (and (setq fname (findfile "test.txt")) (setq dclf (write_dcl)) ) (progn ;; Open the file for reading (setq file (open fname "r") l nil ;; This is not necessary if you localized the "l" variable and can be removed. ) ;; Read in the test.txt file and get the content lines. (while (setq x (read-line file)) (setq l (append l (list x))) ) ;; Close the file. (close file) ;; Load the DCL file name returned by (write_dcl) (setq i (load_dialog dclf)) ;; Initialize the "Example" dialog box (if (not (new_dialog "Example" i)) (exit)) ;; Populate the list box with list "l" (start_list "select" 3) (mapcar 'add_list l) (end_list) ;; Set the current note LIST to the first item in the list. (setq rtn (list (nth 0 l))) ;; Show the first item in the list box as selected. (set_tile "select" "0") ;; Set the action for the list box to get the item(s) selected from the list: ;; The list box returns a STRING with integer #s, you must parse the string and ;; convert them to a list of actual integers, then get the NTH items from the list of notes. (action_tile "select" "(setq rl (mapcar 'atoi (strParse $value \" \")) rtn (mapcar '(lambda (a) (nth a l)) rl))") ;; if the "accept" button is pressed", exit the dialog and return value 1 (action_tile "accept" "(done_dialog 1)") ;; If the "cancel" button is pressed, exit the dialog and return value 0 (action_tile "cancel" "(done_dialog 0)") ;; Run the dialog (setq dcl_ret (start_dialog)) ;; Unload the DCL from Memory (unload_dialog i) ;; Delete the temporary DCL. (vl-file-delete dclf) ;; If the "accept" button was pressed and the note(s) selected, then start ;; the "MLEADER" command and create the note. (if (and rtn (= dcl_ret 1)) (foreach n rtn (command "._mleader" pause pause "" n "") ) ) ) ) ;; Exit Quietly (princ) ); End Defun C:TEST Edited April 4 by pkenewell to add a parsing function for multiple note selection. 2nd Edit to correct some minor typos and errors. Quote
BIGAL Posted April 4 Posted April 4 Just a comment Lee-mac has a nice select multiple from a list DCL it uses 2 list boxes so as you pick a note you add to 2nd list box can remove also before click OK, trying to find again. Quote
Kvlar Posted April 5 Author Posted April 5 9 hours ago, pkenewell said: @Kvlar OK - I took a bit of time and went through your whole code, changing it to what it should look like. Please study it with my comments and ask questions if you really want to learn more. EDIT - I added code for Multiple note selection, which I noticed you were trying to do, but it needed adding a parsing function to separate the list into just the selected items. ;; Made this into a function to return the file name of the DCL if written successfully. ;; Localize your variables! (defun Write_DCL (/ dcl_file tmp-dcl-file-name) ;; Set the dcl file name and open it as a ASCII file for writing (setq dcl_file (open (setq tmp-dcl-file-name (vl-filename-mktemp nil nil ".DCL")) "w")) ;; I removed the (progn) as it is not necessary, and I eliminated some invalid ;; DCL stuff from your DCL list. (foreach x '( "Example : dialog {" " label = \"Test Dialog \";" " : column {" " : row {" " : boxed_column {" " : list_box {" " label =\"Select\";" " key = \"select\";" " height = 20;" " width = 40;" " multiple_select = true;" " value = \"\";" " }" " }" " }" " : row {" " : boxed_row {" " : button {" " key = \"accept\";" " label = \" Select \";" " is_default = true;" " }" " : button {" " key = \"cancel\";" " label = \" Cancel \";" " is_default = false;" " is_cancel = true;" " }" " }" " }" " }" "}" ) (write-line x dcl_file) ) ;; Close the DCL file (close dcl_file) ;; Return the DCL file name if the write is good, otherwise NIL (if (findfile tmp-dcl-file-name) tmp-dcl-file-name nil) ); end defun (write_dcl) ;; Function to parse a string into a list at a delimiter (defun StrParse (str del / pos) (if (and str del) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (StrParse (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) );; end defun (StrParse) ;; Localize your variables! (defun c:test (/ fname dclf dcl_ret i l rl rtn x) ;; Load Viaual LISP functions - for (vl-file-delete) (vl-load-com) ; If the TEST.txt file exists AND the Temporary DCL file is written, then (if (and (setq fname (findfile "test.txt")) (setq dclf (write_dcl)) ) (progn ;; Open the file for reading (setq file (open fname "r") l nil ;; This is not necessary if you localized the "l" variable and can be removed. ) ;; Read in the test.txt file and get the content lines. (while (setq x (read-line file)) (setq l (append l (list x))) ) ;; Close the file. (close file) ;; Load the DCL file name returned by (write_dcl) (setq i (load_dialog dclf)) ;; Initialize the "Example" dialog box (if (not (new_dialog "Example" i)) (exit)) ;; Populate the list box with list "l" (start_list "select" 3) (mapcar 'add_list l) (end_list) ;; Set the current note LIST to the first item in the list. (setq rtn (list (nth 0 l))) ;; Show the first item in the list box as selected. (set_tile "select" "0") ;; Set the action for the list box to get the item(s) selected from the list: ;; The list box returns a STRING with integer #s, you must parse the string and ;; convert them to a list of actual integers, then get the NTH items from the list of notes. (action_tile "select" "(setq rl (mapcar 'atoi (strParse $value \" \")) rtn (mapcar '(lambda (a) (nth a l)) rl))") ;; if the "accept" button is pressed", exit the dialog and return value 1 (action_tile "accept" "(done_dialog 1)") ;; If the "cancel" button is pressed, exit the dialog and return value 0 (action_tile "cancel" "(done_dialog 0)") ;; Run the dialog (setq dcl_ret (start_dialog)) ;; Unload the DCL from Memory (unload_dialog i) ;; Delete the temporary DCL. (vl-file-delete dclf) ;; If the "accept" button was pressed and the note(s) selected, then start ;; the "MLEADER" command and create the note. (if (and rtn (= dcl_ret 1)) (foreach n rtn (command "._mleader" pause pause "" n "") ) ) ) ) ;; Exit Quietly (princ) ); End Defun C:TEST Hi, pennewell Thank you for taking your time, I really appreciate it. I have tried the code you created, but when I tried it, no text appeared when I executed the mleader command Quote
Kvlar Posted April 5 Author Posted April 5 On 4/4/2024 at 6:31 AM, BIGAL said: Did you try my code its all you need. It will pop a dcl list box for you to select an item. You may need to change 20 is width 10 is how many lines to display. I've tried it, but I haven't succeeded in following the suggestions you gave. Looks like I made a mistake in trying it. I'm sorry, I'm still a beginner at this Quote
Kvlar Posted April 5 Author Posted April 5 On 4/4/2024 at 6:31 AM, BIGAL said: Did you try my code its all you need. It will pop a dcl list box for you to select an item. You may need to change 20 is width 10 is how many lines to display. I've tried it again and it works. Thank you very much for your help, you saved my life Quote
Jonathan Handojo Posted April 5 Posted April 5 Here you go. I formatted your code slightly. Most of it remained untouched, I only added one more line to your code: (defun c:test ( / dcl_file file fname i l line rtn tmp-dcl-file-name) ;; |JH| variable localised (setq dcl_file (open (setq tmp-dcl-file-name (vl-filename-mktemp nil nil ".DCL")) "w")) (foreach x '( "Example : dialog" "{" " label = \"Test Dialog \";" ": column" " {" " : row" " {" " : boxed_column" " {" " : list_box" " {" " label =\"Select\";" " key = \"select\";" " height = 20;" " width = 40;" " multiple_select = true;" " value = \"\";" " }" " }" " }" "" " {" "" " }" " : row" " {" " : boxed_row" " {" " : button" " {" " key = \"accept\";" " label = \" Select \";" " is_default = true;" " }" " : button" " {" " key = \"cancel\";" " label = \" Cancel \";" " is_default = false;" " is_cancel = true;" " }" " }" " }" " }" "}" ) (write-line x dcl_file) ) (setq dcl_file (close dcl_file)) (if (setq fname (findfile "test.txt")) (progn (setq file (open fname "r") l nil ) (while (setq line (read-line file)) (setq l (append l (list line))) ) (close file) (setq i (load_dialog tmp-dcl-file-name)) (if (not (new_dialog "Example" i)) (exit)) (start_list "select" 3) (mapcar 'add_list l) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (action_tile "accept" "(setq l (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" (get_tile \"select\") \")\")))) (done_dialog)") ;; |JH| Line added (start_dialog) (unload_dialog i) (foreach a l (command "_mleader" pause pause a) ) ) ) ) Quote
Kvlar Posted April 5 Author Posted April 5 11 minutes ago, Jonathan Handojo said: Here you go. I formatted your code slightly. Most of it remained untouched, I only added one more line to your code: (defun c:test ( / dcl_file file fname i l line rtn tmp-dcl-file-name) ;; |JH| variable localised (setq dcl_file (open (setq tmp-dcl-file-name (vl-filename-mktemp nil nil ".DCL")) "w")) (foreach x '( "Example : dialog" "{" " label = \"Test Dialog \";" ": column" " {" " : row" " {" " : boxed_column" " {" " : list_box" " {" " label =\"Select\";" " key = \"select\";" " height = 20;" " width = 40;" " multiple_select = true;" " value = \"\";" " }" " }" " }" "" " {" "" " }" " : row" " {" " : boxed_row" " {" " : button" " {" " key = \"accept\";" " label = \" Select \";" " is_default = true;" " }" " : button" " {" " key = \"cancel\";" " label = \" Cancel \";" " is_default = false;" " is_cancel = true;" " }" " }" " }" " }" "}" ) (write-line x dcl_file) ) (setq dcl_file (close dcl_file)) (if (setq fname (findfile "test.txt")) (progn (setq file (open fname "r") l nil ) (while (setq line (read-line file)) (setq l (append l (list line))) ) (close file) (setq i (load_dialog tmp-dcl-file-name)) (if (not (new_dialog "Example" i)) (exit)) (start_list "select" 3) (mapcar 'add_list l) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (action_tile "accept" "(setq l (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" (get_tile \"select\") \")\")))) (done_dialog)") ;; |JH| Line added (start_dialog) (unload_dialog i) (foreach a l (command "_mleader" pause pause a) ) ) ) ) it works, you are so cool. thank you very much for your help Quote
Kvlar Posted April 5 Author Posted April 5 you are cool people who want to share and are not stingy with knowledge, I really appreciate it. Thank you very much. my problem has been solved Quote
Jonathan Handojo Posted April 5 Posted April 5 No worries. Happy to help out. Most of who I know here are always very helpful and always share their knowledge. Which is why I like this site. Learn something new each time. 1 Quote
Kvlar Posted April 5 Author Posted April 5 (edited) hello again. I tried to make something new with the same concept as before. The difference is that previously I created a multileader, now I try to fill in the value of the attribute block based on the DCL list box. and I input the contents of the dcl list box from the txt file. This is the code I'm trying to create : (setq dcl_file (open (setq tmp-dcl-file-name (vl-filename-mktemp nil nil ".DCL")) "w")) (progn (foreach x '( "ROOMNAME : dialog {" " label = \"testing\"; " " : column {" " : row {" " : boxed_column {" " : list_box { " " label =\"Select\";" " key = \"mylist\";" " height = 10;" " width = 30;" " multiple_select = false; " " value = \"\";" " }" " }" " }" " : edit_box {" " label = \"Input : \";" " key = \"userinput\";" " edit_width = 20;" " value = \"FFL \\U+00B1 0.00\";" " }" " : row {" " : boxed_row {" " : button {" " key = \"accept\";" " label = \" Select \";" " is_default = true;" " }" " : button {" " key = \"cancel\";" " label = \" Cancel \";" " is_default = false;" " is_cancel = true;" " }" " }" " }" " }" "}" ) (write-line x dcl_file) ) (setq dcl_file (close dcl_file))) (setq elev(get_tile "userinput")) (defun C:RN() (if (setq fname (findfile "test.txt")) (progn (setq file (open fname "r") l nil) (while (setq line (read-line file)) (setq l (append l (list line))) ) (close file) (setq i (load_dialog tmp-dcl-file-name)) (if (not (new_dialog "ROOMMAME" i)) (exit)) (start_list "mylist" 3) (mapcar 'add_list l) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (action_tile "accept" "(setq l (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" (get_tile \"mylist\") \")\")))) (done_dialog)") ;; |JH| Line added (start_dialog) (unload_dialog i) (foreach room l (setq p1(getpoint "\nSelect a point:")) (setq oAttreq(getvar 'attreq)) (setq oAttdia(getvar 'attdia)) (setvar 'attreq 1) (setvar 'attdia 0) (command "-INSERT" "floorplan" p1 1 1 0 eiev room) (setvar 'attreq oAttreq) (setvar 'attdia oAttdia) ) ) ) ) ) ) (princ) ) Edited April 5 by Kvlar Quote
Kvlar Posted April 5 Author Posted April 5 (edited) and this is the object block file that I use Edited April 5 by Kvlar 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.