Author Topic: Popup List  (Read 819 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 462
Popup List
« on: January 17, 2024, 02:57:24 AM »
Currently I am starting a small routine that will use a popup list in DCL.
I don't know how to get the popup list works with edit box in lisp file.

The DCL code is listed below.
A DCL file is also attached for your help.

I will use the code creating a text. The text will have a prefix and a short text label.
In this practice there will be 5 prefixes in popup list.

Prefix   Note
A         XXXXX
B         XXXXX
C         XXXXX
D         XXXXX
E         XXXXX

The "Prefix" will be up to 3 characters while "Note" will be mixed with letters and numbers.

Here is examples that I'd like to get.
A-12345
BNN-123A
Code: [Select]
(strcat Prefix "-" Note)

Your helps are much appreciated.



Code: [Select]
//DCL File For Popup List Test;

PLtest : dialog
{ label = "PopupList Test";
: row {
fixed_width = true;
: boxed_column {
fixed_width = true;
label = "Prefix";
: popup_list {
key = "Prefix";
edit_width = 10;
fixed_width = true;
}
}
: boxed_column {
width = 12;
fixed_width = true;
label = "Note";
: edit_box {
key = "Note";
edit_width = 30;
fixed_width = true;
}
}
}
spacer_1;
: row {ok_cancel;}
}

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Popup List
« Reply #1 on: January 17, 2024, 09:04:19 AM »
What specifically is your question here?

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Popup List
« Reply #2 on: January 17, 2024, 09:35:54 AM »
Currently I am starting a small routine that will use a popup list in DCL.
I don't know how to get the popup list works with edit box in lisp file.

I think the OP is asking how to populate the Popup list and use it with the Edit Box. Consider the function below:
Code - Auto/Visual Lisp: [Select]
  1. (defun run_dialog (/ id lst prf note res ret)  
  2.    (setq lst '("ABC" "DEF" "GHI")
  3.          note "default"
  4.          prf (nth 0 lst)
  5.          res (strcat prf "-" note)
  6.    )
  7.  
  8.    ;; Load the DCL file
  9.    (setq id (load_dialog "Popup List Sample.dcl"))
  10.    ;; Initialize the Dialog Box.
  11.    (new_dialog "PLtest" id)
  12.    
  13.    ;; Populate the Popup List with the list specified.
  14.    (start_list "Prefix")
  15.    (mapcar 'add_list lst)
  16.    (end_list)
  17.  
  18.    ;; Set the initial tile values. Note - the Selected item in the Popup list is a string containing the index of the list.
  19.    (set_tile "Prefix" "0")
  20.    (set_tile "Note" note)
  21.  
  22.    ;; Establish the actions for the tiles. Notice all is encapsulated within the string, including the resultant combined string.
  23.    ;; both the "Prefix" tile and the "Note" tile update the resultant combined string.
  24.    (action_tile "Prefix" "(setq prf (nth (atoi $value) lst) res (strcat prf \"-\" note))")
  25.    (action_tile "Note" "(setq note $value res (strcat prf \"-\" note))")
  26.    
  27.    ;; Exit Actions
  28.    (action_tile "accept" "(done_dialog 1)")
  29.    (action_tile "cancel" "(done_dialog 0)")
  30.  
  31.    ;; Save the exit action and start the dialog.
  32.    (setq ret (start_dialog))
  33.    ;; Unload the Dialog after Exit
  34.    (unload_dialog id)
  35.  
  36.    ;; If the dialog exit action is 1, then return the combined string.
  37.    (if (= ret 1) res nil)
  38. )
  39.  
« Last Edit: January 18, 2024, 11:46:01 AM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Popup List
« Reply #3 on: January 18, 2024, 09:49:32 PM »
Maybe this but be aware supports only about 20 lines. Can pick from column 1 and column 2 then join together. If that suits just ask and will post code its a library function use in any code.

example code
Code: [Select]
(if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp"))
[code](setq lst1 (list "Select Num" "1" "2" "3" "4" "5" "6" "Exit"))
(setq lst2 (list "Select section" "S1" "S2" "S3" "S4" "S5" "S6" "S7" "S8" "S9" "S10"))
(ah:buttscol ah:but ah:but2 "Please select " lst1 lst2)
(setq ans (strcat (nth ah:2col lst1) (nth ah:2col2 lst2)))



« Last Edit: January 18, 2024, 09:53:12 PM by BIGAL »
A man who never made a mistake never made anything

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Popup List
« Reply #4 on: January 22, 2024, 05:54:16 AM »
Thanks to everyone's help.
:)

I was also thinking about using radio buttons. But in my case I decided to use popup list. I will create another piece that using radio buttons. :)

Finally I paste the code here.
Is there anything to be improved?

Code: [Select]
(defun c:InsertText (/ dcl_id1 sort_list Prefix Note AddPrefix)


(setq dcl_id1 (load_dialog "Popup List Sample.dcl"))
(if (not (new_dialog "PLtest" dcl_id1))
(exit)
); end of if

(setq sort_list '("Add Prefix" "L01" "L02" "L03" "L04" "L05"))

(start_list "Prefix")
(mapcar 'add_list sort_list)
(end_list)

(if Prefix
    (set_tile "Prefix" Prefix)
    (set_tile "Prefix" "0")
); end of if

(if Note
    (set_tile "Note" Note)
); end of if

(setq Prefix (get_tile "Prefix"))
(setq Note (strcase (get_tile "Note")))

(action_tile "Prefix" "(setq Prefix $value)")
(action_tile "Note" "(setq Note $value)")

(action_tile "accept" "(setq start_ok T) Prefix (done_dialog 1)")
(action_tile "cancel" "(setq start_ok nil)(done_dialog 0)")

(start_dialog)
(unload_dialog dcl_id1)

(cond ((= Prefix "0")              ; [color=red]Does it required?[/color]
   (setq NoDisplay "No")   ; [color=red]Does it required?[/color]
  ); end of cond 00        ; [color=red]Does it required?[/color]
  ((= Prefix "1")
   (setq AddPrefix "L01")
  ); end of cond 01
  ((= Prefix "2")
   (setq AddPrefix "L02")
  ); end of cond 02
  ((= Prefix "3")
   (setq AddPrefix "L03")
  ); end of cond 03
  ((= Prefix "4")
   (setq AddPrefix "L04")
  ); end of cond 04
  ((= Prefix "5")
   (setq AddPrefix "L05")
  ); end of cond 05
); end of cond


(command "_.text" (getpoint "insert text") "" "" (strcat AddPrefix "-" Note))

(princ)
); end of InsertText

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Popup List
« Reply #5 on: January 22, 2024, 12:40:57 PM »
Thanks to everyone's help.
:)

I was also thinking about using radio buttons. But in my case I decided to use popup list. I will create another piece that using radio buttons. :)

Finally I paste the code here.
Is there anything to be improved?

This will work, but:
1) does not have enough error trapping if the user leaves "note" blank for example.
2) Ignores the list you created and uses a big conditional statement to get the prefix when you could just get it from the list while the DCL is running.
3) the (setq nodisplay "No") does not seem to have any purpose, unless this is not all the code.
4) you should make an effort to make global variables unique so that another program wont overwrite them.

Take a look at this updated code:
Code - Auto/Visual Lisp: [Select]
  1. ;; by PKENEWELL rewrite for Measureup
  2. (defun c:InsertText (/ *error* ce id lst prf res ret)  
  3.    
  4.    (defun *error* (msg)
  5.       (setvar "cmdecho" ce)
  6.       (princ msg)
  7.    )
  8.    
  9.    ; Establish the list and get the value of CMDECHO
  10.    (setq lst '("Add Prefix" "L01" "L02" "L03" "L04" "L05") ce (getvar "cmdecho"))
  11.    ;; Set CMDECHO to zero for cleaner command line display.
  12.    (setvar "cmdecho" 0)
  13.    ; Start an UNDO Mark.
  14.    (command "._undo" "_BE")
  15.    ;; If Global prf:index does not exist yet, set to defaults. if it does, set the prefix to the item in the list.
  16.    (if (not prf:index)(setq prf:index "0" prf nil)(setq prf (nth (atoi prf:index) lst)))
  17.    ;; If Global note does not exist, set it to a default value.
  18.    (if (not GL:note)(setq GL:note "Default"))
  19.  
  20.    ; if a prefix is selected and Note is not blank, set the resulting text string.
  21.    (if (and prf (/= GL:note ""))(setq res (strcat prf "-" GL:note)))
  22.  
  23.    ;; Load the DCL file
  24.    (setq id (load_dialog "Popup List Sample.dcl"))
  25.    ;; Initialize the Dialog Box.
  26.    (if (not (new_dialog "PLtest" id))
  27.        (progn (unload_dialog id)(exit))
  28.    )
  29.    
  30.    ;; Populate the Popup List with the list specified.
  31.    (start_list "Prefix")
  32.    (mapcar 'add_list lst)
  33.    (end_list)
  34.  
  35.    ;; Set the initial tile values. Note - the Selected item in the Popup list is a string containing the index of the list.
  36.    (set_tile "Prefix" prf:index)
  37.    (set_tile "Note" GL:note)
  38.  
  39.    ;; Establish the actions for the tiles. Notice all is encapsulated within the string, including the resultant combined string.
  40.    ;; both the "Prefix" tile and the "Note" tile update the resultant combined string.
  41.    (action_tile "Prefix"
  42.       "(if (/= $value \"0\")(setq prf (nth (atoi (setq prf:index $value)) lst) res (strcat prf \"-\" GL:note))(setq prf nil res nil))"
  43.    )
  44.    (action_tile "Note" "(if (/= $value \"\")(setq GL:note $value res (if prf (strcat prf \"-\" GL:note)))(setq res nil))")
  45.    
  46.    ;; Exit Actions
  47.    (action_tile "accept" "(if res (done_dialog 1)(alert \"No Prefix Selected or Note is Blank\"))")
  48.    (action_tile "cancel" "(done_dialog 0)")
  49.  
  50.    ;; Save the exit action and start the dialog.
  51.    (setq ret (start_dialog))
  52.    ;; Unload the Dialog after Exit
  53.    (unload_dialog id)
  54.  
  55.    ;; If the dialog exit action is 1 and there is a resultant string. create the TEXT.
  56.    (if (and res (= ret 1))
  57.       (command "_.text" (getpoint "\n Specify Insertion Point of text: ") "" "" res)
  58.    )
  59.    ; End the UNDO Mark.
  60.    (command "._Undo" "_E")
  61.    (setvar "cmdecho" ce)
  62.    (princ)
  63. )
  64.  
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Popup List
« Reply #6 on: January 29, 2024, 09:19:58 PM »

This will work, but:
1) does not have enough error trapping if the user leaves "note" blank for example.
2) Ignores the list you created and uses a big conditional statement to get the prefix when you could just get it from the list while the DCL is running.
3) the (setq nodisplay "No") does not seem to have any purpose, unless this is not all the code.
4) you should make an effort to make global variables unique so that another program wont overwrite them.


Thanks for your help.
By looking your code I realize you get the list instead of using "get_tile" and as the result your code is both shorter in length and in response time.

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Popup List
« Reply #7 on: January 30, 2024, 10:59:06 AM »
Thanks for your help.
By looking your code I realize you get the list instead of using "get_tile" and as the result your code is both shorter in length and in response time.

No problem. Let me know if you have any other questions about my example code.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt