Author Topic: Help: Dcl lisp to insert text  (Read 516 times)

0 Members and 1 Guest are viewing this topic.

mhy3sx

  • Newt
  • Posts: 120
Help: Dcl lisp to insert text
« on: March 19, 2024, 01:39:18 PM »
I am trying to convert an old lisp to work with dcl menu.
 
I am trying to replace this part of the code with radio buttons

Code - Auto/Visual Lisp: [Select]
  1.  (princ "\n")(princ "\n")(princ "\n")
  2.            (initget "1 2 3 4 5 6")
  3.            (setq
  4.              l
  5.               (cond
  6.                 ((getkword
  7.                    "\nSelect text style:\n1. text style1\n2. text style2\n3. text style3\n4. text style4\n5. text style5\n6.text style6
  8. "
  9.                  )
  10.                 )
  11.                 ("1")
  12.               )
  13.            )
  14.  
  15.      (cond
  16.        ((eq l "1")
  17.         (command "_layer" "_m" "Layer 1" "_c" "253" "" "")
  18.        )
  19.        ((eq l "2")
  20.         (command "_layer" "_m" "Layer 2" "_c" "223" "" "")
  21.        )
  22.        ((eq l "3")
  23.         (command "_layer" "_m" "Layer 3" "_c" "150" "" "")
  24.        )
  25.            ((eq l "4")
  26.         (command "_layer" "_m" "Layer 4" "_c" "43" "" "")
  27.        )
  28.        ((eq l "5")
  29.         (command "_layer" "_m" "Layer 5" "_c" "7" "" "")
  30.            )
  31.        ((eq l "6")
  32.         (command "_layer" "m" "Layer 6" "_c" "7" "" "")
  33.        )
  34.      )
  35. )
  36.  
  37.  



Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:foo ( / *error* dch dcl des len wid len1 wid1 ar1 len2 wid2 ar2)
  3.   (defun *error* ( msg )
  4.     (if (and (= 'int (type dch)) (< 0 dch))
  5.              (unload_dialog dch)
  6.     )
  7.     (if (= 'file (type des))
  8.                 (close des)
  9.     )
  10.     (if (and (= 'str (type dcl)) (findfile dcl))
  11.              (vl-file-delete dcl)
  12.     )
  13.     (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
  14.          (princ (strcat "\nError: " msg))
  15.     )
  16.     (princ)
  17.   ) ; end defun 2
  18.  
  19.  
  20.  
  21.  
  22.  
  23.   (cond
  24.     ( (not
  25.       (setq dcl (vl-filename-mktemp nil nil ".dcl")
  26.             des (open dcl "w")
  27.       ) ; end setq
  28.       ) ; end not
  29.       (princ "\nUnable to open DCL for writing.")
  30.     )
  31.     ( (progn
  32.       (foreach str '(
  33. "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}"
  34. ""
  35. "foo : dialog { spacer; key = \"dcl\";"
  36. " : boxed_row { label = \"text style\";"
  37. "      : radio_button { { height = 1.0; width = 20; is_tab_stop = true;"
  38. "      : ed { key = \"radio_button01\"; label = \"Text Style 1\"; }"
  39. "    }" ; radio_button
  40. " : boxed_row { label = \"text style\";"
  41. "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  42. "      : ed { key = \"radio_button02\"; label = \"Text Style 2\"; }"
  43. "    }" ; radio_button
  44. "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  45. "      : ed { key = \"radio_button03\"; label = \"Text Style 3\"; }"
  46. "    }" ; radio_button
  47. "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  48. "      : ed { key = \"radio_button04\"; label = \"Text Style 4\"; }"
  49. "    }" ; radio_button
  50. "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  51. "      : ed { key = \"radio_button05\"; label = \"Text Style 5\"; }"
  52. "    }" ; radio_button
  53. "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  54. "      : ed { key = \"radio_button06\"; label = \"Text Style 6\"; }"
  55. "    }" ; radio_button
  56. "    : column { width = 17;"
  57. "      : button { key = \"OK\"; label = \"OK\"; is_default = true;"
  58. "                 is_cancel = true; fixed_width = true; width = 10; }"
  59. "    }" ; end column
  60. "    : column { width = 16;"
  61. "    }"
  62. "  }"
  63. "}" ; end dialog
  64.  
  65.  
  66.       ) ;end list
  67.       (write-line str des)
  68.     ) ; end foreach
  69.     (setq des (close des)
  70.           dch (load_dialog dcl)
  71.     ) ; end setq
  72.     (<= dch 0)
  73.   )
  74.   (princ "\nUnable to load DCL file.")
  75.             )
  76.             (   (not (new_dialog "foo" dch))
  77.                 (princ "\nUnable to display 'foo' dialog.")
  78.             )
  79.             (   t
  80.                 (set_tile "dcl"     "text Oprions")
  81.                 (action_tile "radio_button01" "(setq sngReturn 1)")
  82.                 (action_tile "radio_button02" "(setq sngReturn 2)")
  83.                 (action_tile "radio_button03" "(setq sngReturn 3)")
  84.                 (action_tile "radio_button04" "(setq sngReturn 4)")
  85.                 (action_tile "radio_button05" "(setq sngReturn 5)")
  86.                 (action_tile "radio_button06" "(setq sngReturn 6)")
  87.                 (action_tile "OK"   "(done_dialog 1)")
  88.  
  89.       (start_dialog)
  90.       )
  91.     ) ; end cond 1
  92.   (*error* nil)
  93.   (princ)
  94. ) ; end defun
  95.  
  96.  


Can any one help me?
Thanks

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Help: Dcl lisp to insert text
« Reply #1 on: March 19, 2024, 05:42:49 PM »
I hope you wished to implement creation of predefined Layers and not Text Styles, though DCL is called Text Styles...
Here is my intervention that worked on BricsCAD...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / *error* dch dcl des )
  2.  
  3.   (defun *error* ( msg )
  4.     (if (and (= 'int (type dch)) (< 0 dch))
  5.       (unload_dialog dch)
  6.     )
  7.     (if (= 'file (type des))
  8.       (close des)
  9.     )
  10.     (if (and (= 'str (type dcl)) (findfile dcl))
  11.       (vl-file-delete dcl)
  12.     )
  13.     (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
  14.       (princ (strcat "\nError: " msg))
  15.     )
  16.     (princ)
  17.   ) ; end defun
  18.  
  19.   (cond
  20.     ( (not
  21.         (setq dcl (vl-filename-mktemp nil nil ".dcl")
  22.              des (open dcl "w")
  23.         ) ; end setq
  24.       ) ; end not
  25.       (princ "\nUnable to open DCL for writing.")
  26.     )
  27.     ( (progn
  28.         (foreach str '(
  29.                         "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}"
  30.                         ""
  31.                         "foo : dialog { spacer; key = \"dcl\";"
  32.                         " : boxed_column { label = \"Text Style\"; height = 1.0;}"
  33.                         "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  34.                         "        key = \"radio_button01\"; label = \"Text Style 1\";"
  35.                         "    }" ; radio_button
  36.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  37.                         "        key = \"radio_button02\"; label = \"Text Style 2\";"
  38.                         "    }" ; radio_button
  39.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  40.                         "        key = \"radio_button03\"; label = \"Text Style 3\";"
  41.                         "    }" ; radio_button
  42.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  43.                         "        key = \"radio_button04\"; label = \"Text Style 4\";"
  44.                         "    }" ; radio_button
  45.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  46.                         "        key = \"radio_button05\"; label = \"Text Style 5\";"
  47.                         "    }" ; radio_button
  48.                         "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  49.                         "        key = \"radio_button06\"; label = \"Text Style 6\";"
  50.                         "    }" ; radio_button
  51.                         "    : row { width = 20;"
  52.                         "      : button { key = \"OK\"; label = \"OK\"; is_default = true;"
  53.                         "                 is_cancel = true; fixed_width = true; width = 10; }"
  54.                         "    }" ; end row
  55.                         "  }" ; end dialog
  56.                       ) ;end list
  57.           (write-line str des)
  58.         ) ; end foreach
  59.         (setq des (close des)
  60.              dch (load_dialog dcl)
  61.         ) ; end setq
  62.         (<= dch 0)
  63.       )
  64.       (princ "\nUnable to load DCL file.")
  65.     )
  66.     ( (not (new_dialog "foo" dch))
  67.       (princ "\nUnable to display 'foo' dialog.")
  68.     )
  69.     ( t
  70.       (set_tile "dcl" "Text Options")
  71.       (action_tile "radio_button01" "(progn (command \"_.-layer\" \"_m\" \"Layer 1\" \"_c\" \"253\" \"\" \"\") (setq sngReturn 1))")
  72.       (action_tile "radio_button02" "(progn (command \"_.-layer\" \"_m\" \"Layer 2\" \"_c\" \"223\" \"\" \"\") (setq sngReturn 2))")
  73.       (action_tile "radio_button03" "(progn (command \"_.-layer\" \"_m\" \"Layer 3\" \"_c\" \"150\" \"\" \"\") (setq sngReturn 3))")
  74.       (action_tile "radio_button04" "(progn (command \"_.-layer\" \"_m\" \"Layer 4\" \"_c\" \"43\" \"\" \"\") (setq sngReturn 4))")
  75.       (action_tile "radio_button05" "(progn (command \"_.-layer\" \"_m\" \"Layer 5\" \"_c\" \"7\" \"\" \"\") (setq sngReturn 5))")
  76.       (action_tile "radio_button06" "(progn (command \"_.-layer\" \"_m\" \"Layer 6\" \"_c\" \"7\" \"\" \"\") (setq sngReturn 6))")
  77.       (action_tile "OK" "(progn (done_dialog 1) sngReturn)")
  78.       (start_dialog)
  79.     )
  80.   ) ; end cond
  81.   (*error* nil)
  82. ) ; end defun
  83.  
« Last Edit: March 20, 2024, 03:37:27 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1419
  • 40 + years of using Autocad
Re: Help: Dcl lisp to insert text
« Reply #2 on: March 19, 2024, 10:25:44 PM »
Just use this, examples in top of code, did you ask over at Cadtutor as well ?

A man who never made a mistake never made anything

mhy3sx

  • Newt
  • Posts: 120
Re: Help: Dcl lisp to insert text
« Reply #3 on: March 20, 2024, 04:00:18 AM »
Thank you ribarm , BIGAL for the help. The code works fine now.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Help: Dcl lisp to insert text
« Reply #4 on: March 20, 2024, 05:51:39 AM »
In BricsCAD works fine, but in AutoCAD 2022 it shows DCL, but freezes when choosing an option...
This is my recent try, by forming separate (defun)s...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / *error* dch dcl des cmde button01 button02 button03 button04 button05 button06 )
  2.  
  3.   (defun *error* ( msg )
  4.     (if cmde
  5.       (setvar (quote cmdecho) cmde)
  6.     )
  7.     (if (and (= 'int (type dch)) (< 0 dch))
  8.       (unload_dialog dch)
  9.     )
  10.     (if (= 'file (type des))
  11.       (close des)
  12.     )
  13.     (if (and (= 'str (type dcl)) (findfile dcl))
  14.       (vl-file-delete dcl)
  15.     )
  16.     (if (and msg (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  17.       (princ (strcat "\nError: " msg))
  18.       (prompt (strcat "\n" msg))
  19.     )
  20.     (princ)
  21.   ) ; end defun
  22.  
  23.   (setq cmde (getvar (quote cmdecho)))
  24.   (setvar (quote cmdecho) 1)
  25.  
  26.   (defun button01 nil
  27.     (if command-s
  28.       (command-s "_.-layer" "_m" "Layer 1" "_c" 253 "" "")
  29.       (command "_.-layer" "_m" "Layer 1" "_c" 253 "" "")
  30.     )
  31.     (if (not (tblsearch "STYLE" "Style1"))
  32.       (progn
  33.         (command "_.-style" "Style1" "Arial.ttf")
  34.         (while (< 0 (getvar (quote cmdactive)))
  35.           (command "")
  36.         )
  37.       )
  38.       (progn
  39.         (command "_.-style" "Style1")
  40.         (while (< 0 (getvar (quote cmdactive)))
  41.           (command "")
  42.         )
  43.       )
  44.     )
  45.     (if command-s
  46.       (command-s "_.-text" "_S" "Style1" "_J" "_BL" "\\" "\\" "\\")
  47.       (command "_.-text" "_S" "Style1" "_J" "_BL" "\\" "\\" "\\")
  48.     )
  49.   )
  50.  
  51.   (defun button02 nil
  52.     (if command-s
  53.       (command-s "_.-layer" "_m" "Layer 2" "_c" 223 "" "")
  54.       (command "_.-layer" "_m" "Layer 2" "_c" 223 "" "")
  55.     )
  56.     (if (not (tblsearch "STYLE" "Style2"))
  57.       (progn
  58.         (command "_.-style" "Style2" "Times New Roman.ttf")
  59.         (while (< 0 (getvar (quote cmdactive)))
  60.           (command "")
  61.         )
  62.       )
  63.       (progn
  64.         (command "_.-style" "Style2")
  65.         (while (< 0 (getvar (quote cmdactive)))
  66.           (command "")
  67.         )
  68.       )
  69.     )
  70.     (if command-s
  71.       (command-s "_.-text" "_S" "Style2" "_J" "_BL" "\\" "\\" "\\")
  72.       (command "_.-text" "_S" "Style2" "_J" "_BL" "\\" "\\" "\\")
  73.     )
  74.   )
  75.  
  76.   (defun button03 nil
  77.     (if command-s
  78.       (command-s "_.-layer" "_m" "Layer 3" "_c" 150 "" "")
  79.       (command "_.-layer" "_m" "Layer 3" "_c" 150 "" "")
  80.     )
  81.     (if (not (tblsearch "STYLE" "Style3"))
  82.       (progn
  83.         (command "_.-style" "Style3" "Tahoma.ttf")
  84.         (while (< 0 (getvar (quote cmdactive)))
  85.           (command "")
  86.         )
  87.       )
  88.       (progn
  89.         (command "_.-style" "Style3")
  90.         (while (< 0 (getvar (quote cmdactive)))
  91.           (command "")
  92.         )
  93.       )
  94.     )
  95.     (if command-s
  96.       (command-s "_.-text" "_S" "Style3" "_J" "_BL" "\\" "\\" "\\")
  97.       (command "_.-text" "_S" "Style3" "_J" "_BL" "\\" "\\" "\\")
  98.     )
  99.   )
  100.  
  101.   (defun button04 nil
  102.     (if command-s
  103.       (command-s "_.-layer" "_m" "Layer 4" "_c" 43 "" "")
  104.       (command "_.-layer" "_m" "Layer 4" "_c" 43 "" "")
  105.     )
  106.     (if (not (tblsearch "STYLE" "Style4"))
  107.       (progn
  108.         (command "_.-style" "Style4" "Calibri.ttf")
  109.         (while (< 0 (getvar (quote cmdactive)))
  110.           (command "")
  111.         )
  112.       )
  113.       (progn
  114.         (command "_.-style" "Style4")
  115.         (while (< 0 (getvar (quote cmdactive)))
  116.           (command "")
  117.         )
  118.       )
  119.     )
  120.     (if command-s
  121.       (command-s "_.-text" "_S" "Style4" "_J" "_BL" "\\" "\\" "\\")
  122.       (command "_.-text" "_S" "Style4" "_J" "_BL" "\\" "\\" "\\")
  123.     )
  124.   )
  125.  
  126.   (defun button05 nil
  127.     (if command-s
  128.       (command-s "_.-layer" "_m" "Layer 5" "_c" 7 "" "")
  129.       (command "_.-layer" "_m" "Layer 5" "_c" 7 "" "")
  130.     )
  131.     (if (not (tblsearch "STYLE" "Style5"))
  132.       (progn
  133.         (command "_.-style" "Style5" "Century Gothic.ttf")
  134.         (while (< 0 (getvar (quote cmdactive)))
  135.           (command "")
  136.         )
  137.       )
  138.       (progn
  139.         (command "_.-style" "Style5")
  140.         (while (< 0 (getvar (quote cmdactive)))
  141.           (command "")
  142.         )
  143.       )
  144.     )
  145.     (if command-s
  146.       (command-s "_.-text" "_S" "Style5" "_J" "_BL" "\\" "\\" "\\")
  147.       (command "_.-text" "_S" "Style5" "_J" "_BL" "\\" "\\" "\\")
  148.     )
  149.   )
  150.  
  151.   (defun button06 nil
  152.     (if command-s
  153.       (command-s "_.-layer" "_m" "Layer 6" "_c" 7 "" "")
  154.       (command "_.-layer" "_m" "Layer 6" "_c" 7 "" "")
  155.     )
  156.     (if (not (tblsearch "STYLE" "Style6"))
  157.       (progn
  158.         (command "_.-style" "Style6" "Technic.ttf")
  159.         (while (< 0 (getvar (quote cmdactive)))
  160.           (command "")
  161.         )
  162.       )
  163.       (progn
  164.         (command "_.-style" "Style6")
  165.         (while (< 0 (getvar (quote cmdactive)))
  166.           (command "")
  167.         )
  168.       )
  169.     )
  170.     (if command-s
  171.       (command-s "_.-text" "_S" "Style6" "_J" "_BL" "\\" "\\" "\\")
  172.       (command "_.-text" "_S" "Style6" "_J" "_BL" "\\" "\\" "\\")
  173.     )
  174.   )
  175.  
  176.   (cond
  177.     ( (not
  178.         (setq dcl (vl-filename-mktemp nil nil ".dcl")
  179.              des (open dcl "w")
  180.         ) ; end setq
  181.       ) ; end not
  182.       (princ "\nUnable to open DCL for writing.")
  183.     )
  184.     ( (progn
  185.         (foreach str '(
  186.                         "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}"
  187.                         ""
  188.                         "foo : dialog { spacer; key = \"dcl\";"
  189.                         " : boxed_column { label = \"Text Style\"; height = 1.0;}"
  190.                         "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  191.                         "        key = \"radio_button01\"; label = \"Text Style 1\";"
  192.                         "    }" ; radio_button
  193.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  194.                         "        key = \"radio_button02\"; label = \"Text Style 2\";"
  195.                         "    }" ; radio_button
  196.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  197.                         "        key = \"radio_button03\"; label = \"Text Style 3\";"
  198.                         "    }" ; radio_button
  199.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  200.                         "        key = \"radio_button04\"; label = \"Text Style 4\";"
  201.                         "    }" ; radio_button
  202.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  203.                         "        key = \"radio_button05\"; label = \"Text Style 5\";"
  204.                         "    }" ; radio_button
  205.                         "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  206.                         "        key = \"radio_button06\"; label = \"Text Style 6\";"
  207.                         "    }" ; radio_button
  208.                         "    : row { width = 20;"
  209.                         "      : button { key = \"OK\"; label = \"OK\"; is_default = true;"
  210.                         "                 is_cancel = true; fixed_width = true; width = 10; }"
  211.                         "    }" ; end row
  212.                         "  }" ; end dialog
  213.                       ) ;end list
  214.           (write-line str des)
  215.         ) ; end foreach
  216.         (setq des (close des)
  217.              dch (load_dialog dcl)
  218.         ) ; end setq
  219.         (<= dch 0)
  220.       )
  221.       (princ "\nUnable to load DCL file.")
  222.     )
  223.     ( (not (new_dialog "foo" dch))
  224.       (princ "\nUnable to display 'foo' dialog.")
  225.     )
  226.     ( t
  227.       (set_tile "dcl" "Text Options")
  228.       (action_tile "radio_button01" "(progn (button01) (setq sngReturn 1))")
  229.       (action_tile "radio_button02" "(progn (button02) (setq sngReturn 2))")
  230.       (action_tile "radio_button03" "(progn (button03) (setq sngReturn 3))")
  231.       (action_tile "radio_button04" "(progn (button04) (setq sngReturn 4))")
  232.       (action_tile "radio_button05" "(progn (button05) (setq sngReturn 5))")
  233.       (action_tile "radio_button06" "(progn (button06) (setq sngReturn 6))")
  234.       (action_tile "OK" "(done_dialog 1)")
  235.       (start_dialog)
  236.     )
  237.   ) ; end cond
  238.   (*error* (itoa sngReturn))
  239. ) ; end defun
  240.  

M.R.
« Last Edit: March 20, 2024, 03:38:06 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Help: Dcl lisp to insert text
« Reply #5 on: March 20, 2024, 01:52:44 PM »
Can someone confirm that above posted code ^^^^ works fine only in BricsCAD, but in AutoCAD it shows Dialog Box, but when choosing an option AutoCAD freezes and you have to kill AutoCAD session by Ending Task through Task Manager... If that's true (I've checked on PC and Laptop with AutoCAD 2022), can someone propose workaround for AutoCAD program if that's possible...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Hugo

  • Bull Frog
  • Posts: 431
Re: Help: Dcl lisp to insert text
« Reply #6 on: March 20, 2024, 02:03:25 PM »
Yes in Autocad 2024 the dialog box freezes

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: Help: Dcl lisp to insert text
« Reply #7 on: March 20, 2024, 02:47:01 PM »
Can someone confirm that above posted code ^^^^ works fine only in BricsCAD, but in AutoCAD it shows Dialog Box, but when choosing an option AutoCAD freezes and you have to kill AutoCAD session by Ending Task through Task Manager... If that's true (I've checked on PC and Laptop with AutoCAD 2022), can someone propose workaround for AutoCAD program if that's possible...

Marco - In AutoCAD, you cannot run an AutoCAD command while a dialog box is active. you need to (done_dialog), before using the command, command-s, or vl-cmdf functions.
"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

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Help: Dcl lisp to insert text
« Reply #8 on: March 20, 2024, 03:13:17 PM »
I've found alternative solution by using Alan H code he posted...
Here is it... It's working as desired in AutoCAD 2022...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / cmde ah:butts ans button01 button02 button03 button04 button05 button06 )
  2.  
  3. ; Multi button Dialog box for a single choice repalcment of initget
  4. ; By Alan H Feb 2019
  5.  
  6. ; Example code as the radio button click will close the default button setting is required
  7. ; if you have defined a default setting
  8.  
  9. ; (if (not AH:Butts)(load "Multi radio buttons.lsp"))                   ; loads the program if not loaded already
  10. ; (if (= ahdef nil)(setq ahdef 3))                                              ; this is needed to set default button
  11. ; you can reset default button to user pick
  12. ; (setq ans (ah:butts ahdef "V"   '("A B C D " "A" "B" "C" "D" )))      ; ans holds the button picked value as a string
  13.                                                                         ; if you want ans a number use (atof ans) or (atoi ans)
  14.  
  15.  
  16. ; (if (= ahdef nil)(setq ahdef 1))
  17. ; (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
  18. ; (setq ans (ah:butts 1 "h"  '("Metric or imperial " "Metric" "Imperial" "other" "wow"))) ; ans holds the button picked value
  19.  
  20.   (setq cmde (getvar (quote cmdecho)))
  21.   (setvar (quote cmdecho) 1)
  22.  
  23.   (defun AH:Butts (AHdef verhor butlst / fo fname x  k )
  24.     (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
  25.     (write-line  "AHbutts : dialog      {" fo)
  26.     (write-line  (strcat "      label =" (chr 34) (nth 0 butlst) (chr 34) " ;" )fo)
  27.     (write-line "       : row   {" fo)
  28.     (if (=  (strcase verhor) "V")
  29.       (progn
  30.         (write-line "   : boxed_radio_column    {" fo)
  31.         (write-line "fixed_width=true;" fo)
  32.         (write-line  (strcat " width = " (rtos (+ (strlen (nth 0 butlst)) 10) 2 0) " ;")  fo)           ; increase 10 if label does not appear
  33.       )
  34.       (progn
  35.         (write-line "   : boxed_radio_row       {" fo)
  36.         (write-line  (strcat " width = " (rtos (+ (strlen (nth 0 butlst)) 10) 2 0) " ;")  fo)           ; increase 10 if label does not appear
  37.       )
  38.     )
  39.     (setq x 1)
  40.     (repeat (- (length butlst) 1)
  41.       (write-line "     : radio_button  {" fo)
  42.       (write-line  (strcat "key = "  (chr 34) "Rb" (rtos x 2 0)  (chr 34) ";") fo)
  43.       (write-line  (strcat "label = " (chr 34) (nth x  butlst) (chr 34) ";") fo)
  44.       (write-line "     }" fo)
  45.       (write-line "spacer_1 ;" fo)
  46.       (setq x (+ x 1))
  47.     )
  48.     (write-line "       }" fo)
  49.     (write-line "       }" fo)
  50.     (write-line "spacer_1 ;" fo)
  51.     (write-line "       ok_only;" fo)
  52.     (write-line "       }" fo)
  53.     (close fo)
  54.     (setq dcl_id (load_dialog fname))
  55.     (if (not (new_dialog "AHbutts" dcl_id) )
  56.       (exit)
  57.     )
  58.     (setq x 1)
  59.     (set_tile (strcat "Rb"  (rtos ahdef 2 0) ) "1")
  60.     (repeat (- (length butlst) 1)
  61.       (setq k (strcat "Rb" (rtos x 2 0)))
  62.       (action_tile k (strcat "(setq but " (rtos x 2 0) ")" "(done_dialog)"))
  63.       (if (= ahdef x) (set_tile k "1"))
  64.       (setq x (+ x 1))
  65.     )
  66.  
  67.     (action_tile "accept" (strcat "(setq but " (rtos ahdef 2 0) ")" "(done_dialog)"))
  68.     (start_dialog)
  69.     (unload_dialog dcl_id)
  70.     (vl-file-delete fname)
  71.     (nth but butlst)
  72.   )
  73.  
  74.   (defun button01 nil
  75.     (if command-s
  76.       (command-s "_.-layer" "_m" "Layer 1" "_c" 253 "" "")
  77.       (command "_.-layer" "_m" "Layer 1" "_c" 253 "" "")
  78.     )
  79.     (if (not (tblsearch "STYLE" "Style1"))
  80.       (progn
  81.         (command "_.-style" "Style1" "Arial.ttf")
  82.         (while (< 0 (getvar (quote cmdactive)))
  83.           (command "")
  84.         )
  85.       )
  86.       (progn
  87.         (command "_.-style" "Style1")
  88.         (while (< 0 (getvar (quote cmdactive)))
  89.           (command "")
  90.         )
  91.       )
  92.     )
  93.     (if command-s
  94.       (command-s "_.-text" "_S" "Style1" "_J" "_BL" "\\" "\\" "\\")
  95.       (command "_.-text" "_S" "Style1" "_J" "_BL" "\\" "\\" "\\")
  96.     )
  97.   )
  98.  
  99.   (defun button02 nil
  100.     (if command-s
  101.       (command-s "_.-layer" "_m" "Layer 2" "_c" 223 "" "")
  102.       (command "_.-layer" "_m" "Layer 2" "_c" 223 "" "")
  103.     )
  104.     (if (not (tblsearch "STYLE" "Style2"))
  105.       (progn
  106.         (command "_.-style" "Style2" "Times New Roman.ttf")
  107.         (while (< 0 (getvar (quote cmdactive)))
  108.           (command "")
  109.         )
  110.       )
  111.       (progn
  112.         (command "_.-style" "Style2")
  113.         (while (< 0 (getvar (quote cmdactive)))
  114.           (command "")
  115.         )
  116.       )
  117.     )
  118.     (if command-s
  119.       (command-s "_.-text" "_S" "Style2" "_J" "_BL" "\\" "\\" "\\")
  120.       (command "_.-text" "_S" "Style2" "_J" "_BL" "\\" "\\" "\\")
  121.     )
  122.   )
  123.  
  124.   (defun button03 nil
  125.     (if command-s
  126.       (command-s "_.-layer" "_m" "Layer 3" "_c" 150 "" "")
  127.       (command "_.-layer" "_m" "Layer 3" "_c" 150 "" "")
  128.     )
  129.     (if (not (tblsearch "STYLE" "Style3"))
  130.       (progn
  131.         (command "_.-style" "Style3" "Tahoma.ttf")
  132.         (while (< 0 (getvar (quote cmdactive)))
  133.           (command "")
  134.         )
  135.       )
  136.       (progn
  137.         (command "_.-style" "Style3")
  138.         (while (< 0 (getvar (quote cmdactive)))
  139.           (command "")
  140.         )
  141.       )
  142.     )
  143.     (if command-s
  144.       (command-s "_.-text" "_S" "Style3" "_J" "_BL" "\\" "\\" "\\")
  145.       (command "_.-text" "_S" "Style3" "_J" "_BL" "\\" "\\" "\\")
  146.     )
  147.   )
  148.  
  149.   (defun button04 nil
  150.     (if command-s
  151.       (command-s "_.-layer" "_m" "Layer 4" "_c" 43 "" "")
  152.       (command "_.-layer" "_m" "Layer 4" "_c" 43 "" "")
  153.     )
  154.     (if (not (tblsearch "STYLE" "Style4"))
  155.       (progn
  156.         (command "_.-style" "Style4" "Calibri.ttf")
  157.         (while (< 0 (getvar (quote cmdactive)))
  158.           (command "")
  159.         )
  160.       )
  161.       (progn
  162.         (command "_.-style" "Style4")
  163.         (while (< 0 (getvar (quote cmdactive)))
  164.           (command "")
  165.         )
  166.       )
  167.     )
  168.     (if command-s
  169.       (command-s "_.-text" "_S" "Style4" "_J" "_BL" "\\" "\\" "\\")
  170.       (command "_.-text" "_S" "Style4" "_J" "_BL" "\\" "\\" "\\")
  171.     )
  172.   )
  173.  
  174.   (defun button05 nil
  175.     (if command-s
  176.       (command-s "_.-layer" "_m" "Layer 5" "_c" 7 "" "")
  177.       (command "_.-layer" "_m" "Layer 5" "_c" 7 "" "")
  178.     )
  179.     (if (not (tblsearch "STYLE" "Style5"))
  180.       (progn
  181.         (command "_.-style" "Style5" "Century Gothic.ttf")
  182.         (while (< 0 (getvar (quote cmdactive)))
  183.           (command "")
  184.         )
  185.       )
  186.       (progn
  187.         (command "_.-style" "Style5")
  188.         (while (< 0 (getvar (quote cmdactive)))
  189.           (command "")
  190.         )
  191.       )
  192.     )
  193.     (if command-s
  194.       (command-s "_.-text" "_S" "Style5" "_J" "_BL" "\\" "\\" "\\")
  195.       (command "_.-text" "_S" "Style5" "_J" "_BL" "\\" "\\" "\\")
  196.     )
  197.   )
  198.  
  199.   (defun button06 nil
  200.     (if command-s
  201.       (command-s "_.-layer" "_m" "Layer 6" "_c" 7 "" "")
  202.       (command "_.-layer" "_m" "Layer 6" "_c" 7 "" "")
  203.     )
  204.     (if (not (tblsearch "STYLE" "Style6"))
  205.       (progn
  206.         (command "_.-style" "Style6" "Technic.ttf")
  207.         (while (< 0 (getvar (quote cmdactive)))
  208.           (command "")
  209.         )
  210.       )
  211.       (progn
  212.         (command "_.-style" "Style6")
  213.         (while (< 0 (getvar (quote cmdactive)))
  214.           (command "")
  215.         )
  216.       )
  217.     )
  218.     (if command-s
  219.       (command-s "_.-text" "_S" "Style6" "_J" "_BL" "\\" "\\" "\\")
  220.       (command "_.-text" "_S" "Style6" "_J" "_BL" "\\" "\\" "\\")
  221.     )
  222.   )
  223.  
  224. ; (if (not AH:Butts) (load "Multi Radio buttons.lsp"))
  225.   (if (= ahdef nil) (setq ahdef 1))
  226.   (setq ans (atoi (ah:butts ahdef "V" '("Choose a number" "1" "2" "3" "4" "5" "6")))) ; ans holds the button picked as an integer value
  227.  
  228.   (cond
  229.     ( (= ans 1)
  230.       (button01)
  231.     )
  232.     ( (= ans 2)
  233.       (button02)
  234.     )
  235.     ( (= ans 3)
  236.       (button03)
  237.     )
  238.     ( (= ans 4)
  239.       (button04)
  240.     )
  241.     ( (= ans 5)
  242.       (button05)
  243.     )
  244.     ( (= ans 6)
  245.       (button06)
  246.     )
  247.   )
  248.   (setvar (quote cmdecho) cmde)
  249.   (prompt (itoa ans))
  250.   (princ)
  251. )
  252.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Help: Dcl lisp to insert text
« Reply #9 on: March 20, 2024, 04:45:00 PM »
@PKENEWELL was right...
I've cured what was trouble with OP's original DCL and rest of code...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:6_styles ( / *error* dch dcl des cmde button01 button02 button03 button04 button05 button06 sngReturn )
  2.  
  3.   (defun *error* ( msg )
  4.     (if cmde
  5.       (setvar (quote cmdecho) cmde)
  6.     )
  7.     (if (and (= 'int (type dch)) (< 0 dch))
  8.       (unload_dialog dch)
  9.     )
  10.     (if (= 'file (type des))
  11.       (close des)
  12.     )
  13.     (if (and (= 'str (type dcl)) (findfile dcl))
  14.       (vl-file-delete dcl)
  15.     )
  16.     (if (and msg (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  17.       (princ (strcat "\nError: " msg))
  18.       (prompt (strcat "\n" msg))
  19.     )
  20.     (princ)
  21.   ) ; end defun
  22.  
  23.   (setq cmde (getvar (quote cmdecho)))
  24.   (setvar (quote cmdecho) 1)
  25.  
  26.   (defun button01 nil
  27.     (if (not (tblsearch "LAYER" "Layer 1"))
  28.       (if command-s
  29.         (command-s "_.-layer" "_m" "Layer 1" "_c" 1 "" "")
  30.         (vl-cmdf "_.-layer" "_m" "Layer 1" "_c" 1 "" "")
  31.       )
  32.       (setvar (quote clayer) "Layer 1")
  33.     )
  34.     (if (not (tblsearch "STYLE" "Style1"))
  35.       (progn
  36.         (vl-cmdf "_.-style" "Style1" "Arial.ttf")
  37.         (while (< 0 (getvar (quote cmdactive)))
  38.           (vl-cmdf "")
  39.         )
  40.       )
  41.       (progn
  42.         (vl-cmdf "_.-style" "Style1")
  43.         (while (< 0 (getvar (quote cmdactive)))
  44.           (vl-cmdf "")
  45.         )
  46.       )
  47.     )
  48.     (if command-s
  49.       (command-s "_.-text" "_S" "Style1" "_J" "_BL" "\\" "\\" "\\")
  50.       (vl-cmdf "_.-text" "_S" "Style1" "_J" "_BL" "\\" "\\" "\\")
  51.     )
  52.   )
  53.  
  54.   (defun button02 nil
  55.     (if (not (tblsearch "LAYER" "Layer 2"))
  56.       (if command-s
  57.         (command-s "_.-layer" "_m" "Layer 2" "_c" 2 "" "")
  58.         (vl-cmdf "_.-layer" "_m" "Layer 2" "_c" 2 "" "")
  59.       )
  60.       (setvar (quote clayer) "Layer 2")
  61.     )
  62.     (if (not (tblsearch "STYLE" "Style2"))
  63.       (progn
  64.         (vl-cmdf "_.-style" "Style2" "Times New Roman.ttf")
  65.         (while (< 0 (getvar (quote cmdactive)))
  66.           (vl-cmdf "")
  67.         )
  68.       )
  69.       (progn
  70.         (vl-cmdf "_.-style" "Style2")
  71.         (while (< 0 (getvar (quote cmdactive)))
  72.           (vl-cmdf "")
  73.         )
  74.       )
  75.     )
  76.     (if command-s
  77.       (command-s "_.-text" "_S" "Style2" "_J" "_BL" "\\" "\\" "\\")
  78.       (vl-cmdf "_.-text" "_S" "Style2" "_J" "_BL" "\\" "\\" "\\")
  79.     )
  80.   )
  81.  
  82.   (defun button03 nil
  83.     (if (not (tblsearch "LAYER" "Layer 3"))
  84.       (if command-s
  85.         (command-s "_.-layer" "_m" "Layer 3" "_c" 3 "" "")
  86.         (vl-cmdf "_.-layer" "_m" "Layer 3" "_c" 3 "" "")
  87.       )
  88.       (setvar (quote clayer) "Layer 3")
  89.     )
  90.     (if (not (tblsearch "STYLE" "Style3"))
  91.       (progn
  92.         (vl-cmdf "_.-style" "Style3" "Tahoma.ttf")
  93.         (while (< 0 (getvar (quote cmdactive)))
  94.           (vl-cmdf "")
  95.         )
  96.       )
  97.       (progn
  98.         (vl-cmdf "_.-style" "Style3")
  99.         (while (< 0 (getvar (quote cmdactive)))
  100.           (vl-cmdf "")
  101.         )
  102.       )
  103.     )
  104.     (if command-s
  105.       (command-s "_.-text" "_S" "Style3" "_J" "_BL" "\\" "\\" "\\")
  106.       (vl-cmdf "_.-text" "_S" "Style3" "_J" "_BL" "\\" "\\" "\\")
  107.     )
  108.   )
  109.  
  110.   (defun button04 nil
  111.     (if (not (tblsearch "LAYER" "Layer 4"))
  112.       (if command-s
  113.         (command-s "_.-layer" "_m" "Layer 4" "_c" 4 "" "")
  114.         (vl-cmdf "_.-layer" "_m" "Layer 4" "_c" 4 "" "")
  115.       )
  116.       (setvar (quote clayer) "Layer 4")
  117.     )
  118.     (if (not (tblsearch "STYLE" "Style4"))
  119.       (progn
  120.         (vl-cmdf "_.-style" "Style4" "Calibri.ttf")
  121.         (while (< 0 (getvar (quote cmdactive)))
  122.           (vl-cmdf "")
  123.         )
  124.       )
  125.       (progn
  126.         (vl-cmdf "_.-style" "Style4")
  127.         (while (< 0 (getvar (quote cmdactive)))
  128.           (vl-cmdf "")
  129.         )
  130.       )
  131.     )
  132.     (if command-s
  133.       (command-s "_.-text" "_S" "Style4" "_J" "_BL" "\\" "\\" "\\")
  134.       (vl-cmdf "_.-text" "_S" "Style4" "_J" "_BL" "\\" "\\" "\\")
  135.     )
  136.   )
  137.  
  138.   (defun button05 nil
  139.     (if (not (tblsearch "LAYER" "Layer 5"))
  140.       (if command-s
  141.         (command-s "_.-layer" "_m" "Layer 5" "_c" 5 "" "")
  142.         (vl-cmdf "_.-layer" "_m" "Layer 5" "_c" 5 "" "")
  143.       )
  144.       (setvar (quote clayer) "Layer 5")
  145.     )
  146.     (if (not (tblsearch "STYLE" "Style5"))
  147.       (progn
  148.         (vl-cmdf "_.-style" "Style5" "Century Gothic.ttf")
  149.         (while (< 0 (getvar (quote cmdactive)))
  150.           (vl-cmdf "")
  151.         )
  152.       )
  153.       (progn
  154.         (vl-cmdf "_.-style" "Style5")
  155.         (while (< 0 (getvar (quote cmdactive)))
  156.           (vl-cmdf "")
  157.         )
  158.       )
  159.     )
  160.     (if command-s
  161.       (command-s "_.-text" "_S" "Style5" "_J" "_BL" "\\" "\\" "\\")
  162.       (vl-cmdf "_.-text" "_S" "Style5" "_J" "_BL" "\\" "\\" "\\")
  163.     )
  164.   )
  165.  
  166.   (defun button06 nil
  167.     (if (not (tblsearch "LAYER" "Layer 6"))
  168.       (if command-s
  169.         (command-s "_.-layer" "_m" "Layer 6" "_c" 6 "" "")
  170.         (vl-cmdf "_.-layer" "_m" "Layer 6" "_c" 6 "" "")
  171.       )
  172.       (setvar (quote clayer) "Layer 6")
  173.     )
  174.     (if (not (tblsearch "STYLE" "Style6"))
  175.       (progn
  176.         (vl-cmdf "_.-style" "Style6" "Technic.ttf")
  177.         (while (< 0 (getvar (quote cmdactive)))
  178.           (vl-cmdf "")
  179.         )
  180.       )
  181.       (progn
  182.         (vl-cmdf "_.-style" "Style6")
  183.         (while (< 0 (getvar (quote cmdactive)))
  184.           (vl-cmdf "")
  185.         )
  186.       )
  187.     )
  188.     (if command-s
  189.       (command-s "_.-text" "_S" "Style6" "_J" "_BL" "\\" "\\" "\\")
  190.       (vl-cmdf "_.-text" "_S" "Style6" "_J" "_BL" "\\" "\\" "\\")
  191.     )
  192.   )
  193.  
  194.   (cond
  195.     ( (not
  196.         (setq dcl (vl-filename-mktemp nil nil ".dcl")
  197.              des (open dcl "w")
  198.         ) ; end setq
  199.       ) ; end not
  200.       (princ "\nUnable to open DCL for writing.")
  201.     )
  202.     ( (progn
  203.         (foreach str '(
  204.                         "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}"
  205.                         ""
  206.                         "foo : dialog { spacer; key = \"dcl\";"
  207.                         " : boxed_column { label = \"Text Style\"; height = 1.0;}"
  208.                         "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  209.                         "        key = \"radio_button01\"; label = \"Text Style 1\";"
  210.                         "    }" ; radio_button
  211.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  212.                         "        key = \"radio_button02\"; label = \"Text Style 2\";"
  213.                         "    }" ; radio_button
  214.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  215.                         "        key = \"radio_button03\"; label = \"Text Style 3\";"
  216.                         "    }" ; radio_button
  217.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  218.                         "        key = \"radio_button04\"; label = \"Text Style 4\";"
  219.                         "    }" ; radio_button
  220.                         "      : radio_button  { height = 1.0; width = 20; is_tab_stop = true;"
  221.                         "        key = \"radio_button05\"; label = \"Text Style 5\";"
  222.                         "    }" ; radio_button
  223.                         "      : radio_button { height = 1.0; width = 20; is_tab_stop = true;"
  224.                         "        key = \"radio_button06\"; label = \"Text Style 6\";"
  225.                         "    }" ; radio_button
  226.                         "    : row { width = 20;"
  227.                         "      : button { key = \"OK\"; label = \"OK\"; is_default = true;"
  228.                         "                 is_cancel = true; fixed_width = true; width = 10; }"
  229.                         "    }" ; end row
  230.                         "  }" ; end dialog
  231.                       ) ;end list
  232.           (write-line str des)
  233.         ) ; end foreach
  234.         (setq des (close des)
  235.              dch (load_dialog dcl)
  236.         ) ; end setq
  237.         (<= dch 0)
  238.       )
  239.       (princ "\nUnable to load DCL file.")
  240.     )
  241.     ( (not (new_dialog "foo" dch))
  242.       (princ "\nUnable to display 'foo' dialog.")
  243.     )
  244.     ( t
  245.       (set_tile "dcl" "Text Options")
  246.       (action_tile "radio_button01" "(setq sngReturn 1)")
  247.       (action_tile "radio_button02" "(setq sngReturn 2)")
  248.       (action_tile "radio_button03" "(setq sngReturn 3)")
  249.       (action_tile "radio_button04" "(setq sngReturn 4)")
  250.       (action_tile "radio_button05" "(setq sngReturn 5)")
  251.       (action_tile "radio_button06" "(setq sngReturn 6)")
  252.       (action_tile "OK" "(done_dialog 1)")
  253.       (start_dialog)
  254.     )
  255.   ) ; end cond
  256.   (cond
  257.     ( (= sngReturn 1)
  258.       (button01)
  259.     )
  260.     ( (= sngReturn 2)
  261.       (button02)
  262.     )
  263.     ( (= sngReturn 3)
  264.       (button03)
  265.     )
  266.     ( (= sngReturn 4)
  267.       (button04)
  268.     )
  269.     ( (= sngReturn 5)
  270.       (button05)
  271.     )
  272.     ( (= sngReturn 6)
  273.       (button06)
  274.     )
  275.   )    
  276.   (*error* (itoa sngReturn))
  277. ) ; end defun)
  278.  

Regards, M.R.
« Last Edit: March 21, 2024, 05:01:09 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1419
  • 40 + years of using Autocad
Re: Help: Dcl lisp to insert text
« Reply #10 on: March 20, 2024, 07:59:23 PM »
A couple more welcome to use. And 3col radio buttons.

Did try make DCL code at one stage just draw objects using blocks and text for labels, the blocks were the radio buttons, same with toggles, the edit box reads the horizontal scale for the width of the box.

Another is Rlx has a convert dcl to lsp which is real handy.
A man who never made a mistake never made anything