TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HeavyThumper on June 25, 2021, 03:14:19 PM

Title: How can I create a literal list - but with a runtime mod?
Post by: HeavyThumper on June 25, 2021, 03:14:19 PM
I'm trying to dynamically build a DCL. Prior to execution, I know everything about the desired DCL structure...except the desired width. So I have a setup like:

Code - Auto/Visual Lisp: [Select]
  1. (foreach line
  2.   '(
  3.     "sb : dialog {"
  4.     "  label = \"Select Blocks\" ;"
  5.     "  : row {"
  6.     "    : list_box {"
  7.     "      label = \"Defined Blocks\" ;"
  8.     "      key = \"lb_defined\" ;"
  9.     "      width = 30;"
  10.   )
  11.   (write-line line dclTemp)
  12. );foreach
  13.  

The above is just a small extract - the remainder of the DCL is structured correctly to finish. Now, I thought I'd pass the width to my DCL creation function and modify it accordingly. So I changed my list to:

Code - Auto/Visual Lisp: [Select]
  1. (foreach line
  2.   '(
  3.     "sb : dialog {"
  4.     "  label = \"Select Blocks\" ;"
  5.     "  : row {"
  6.     "    : list_box {"
  7.     "      label = \"Defined Blocks\" ;"
  8.     "      key = \"lb_defined\" ;"
  9.     (vl-string-subst (itoa width) "www" "      width = www;" ))
  10.   )
  11.   (write-line line dclTemp)
  12. );foreach
  13.  

This...doesn't work. As a workaround I have a foreach processing the literal list up to the first width occurrence - then I stop the list, explicitly write the width line, and then resume the foreach with another list section. There's gotta be a better way of doing this.

Is the problem that I can't use literals in this way - and need to assign the list(s) to a variable and then perform the needed modifications against that variable? Then the simple foreach would work again.
Title: Re: How can I create a literal list - but with a runtime mod?
Post by: ronjonp on June 25, 2021, 03:52:43 PM
Use (list instead of '(
Code - Auto/Visual Lisp: [Select]
  1. (foreach line (list "sb : dialog {"
  2.                     "  label = \"Select Blocks\" ;"
  3.                     "  : row {"
  4.                     "    : list_box {"
  5.                     "      label = \"Defined Blocks\" ;"
  6.                     "      key = \"lb_defined\" ;"
  7.                     (strcat "      width = " (itoa width) ";")
  8.               )
  9.   (write-line line dcltemp)
  10. )
Title: Re: How can I create a literal list - but with a runtime mod?
Post by: JohnK on June 25, 2021, 03:54:08 PM
I believe you just have to write out the dialog file piece at a time. Below is an example I had from a very long time ago (2003-ish) so I apologize but I've lost all DCL knowledge I had.

Code - Auto/Visual Lisp: [Select]
  1. (defun GetString-dlg (str / dcl_id fn fo)
  2.   (setq fn (vl-filename-mktemp "" "" ".dcl"))
  3.   (setq fo (open fn "w"))
  4.   (setq ValueStr (strcat "value = " str ";"))
  5.   (write-line "stringdlg : dialog {
  6.              label = \"Enter String\";" fo)
  7.   (write-line ": edit_box {
  8.              label = \"\";
  9.              edit_width = 30;
  10.              key = \"stringdlg\";
  11.              is_default = true; " fo)
  12.   (write-line ValueStr fo)
  13.   (write-line "}" fo)
  14.   (write-line ": row {
  15.              alignment   = centered;
  16.              fixed_width = true;
  17.               : button {
  18.               label      = \"OK\";
  19.               key        = \"dcl_accept\";
  20.               width      = 10;
  21.               allow_accept = true;
  22.             }
  23.           }
  24.         }" fo)
  25.    (close fo)
  26.    (setq dcl_id (load_dialog fn))
  27.    (new_dialog "stringdlg" dcl_id)
  28.    (action_tile "stringdlg" "(setq str $value)(done_dialog)")
  29.    (unload_dialog dcl_id)
  30.   str
  31.  )
  32.  



EDIT:
FYI: ronjonp knows more than I. Try his solution first.
Title: Re: How can I create a literal list - but with a runtime mod?
Post by: BIGAL on June 25, 2021, 08:08:22 PM
Changing the width I use a STRLEN to work out how many characters, using a Foreach for a list getting the maximum number of characters then use a fuzz factor like 1.2 * length for width.

For a list box type dcl I use a library approach and demand load a predefined lisp. (if (not listbox)(load "listbox")) so only 2 line of code needed. I use one by AlanjT or another from Lee-mac.

Re library approach I have Multi getvals, Multi radio buttons, Multi toggles, all grow as required from a list so like 3 lines of code is all you need. A Multi column Radio buttons is being worked on now. Go Cadtutuor/downloads there free. All have example code in them.
Title: Re: How can I create a literal list - but with a runtime mod?
Post by: HeavyThumper on June 26, 2021, 02:12:40 PM
Use (list instead of '(

Thank you! Exactly what I needed.
Title: Re: How can I create a literal list - but with a runtime mod?
Post by: Lee Mac on June 30, 2021, 06:19:20 PM
Use (list instead of '(

Thank you! Exactly what I needed.

FWIW, here's (http://lee-mac.com/quote.html) the 'why'.