Author Topic: Radio_button controls and list boxes.  (Read 232 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Newt
  • Posts: 132
Radio_button controls and list boxes.
« on: February 13, 2020, 07:21:15 PM »
When user pics Draw Line the "Select Layer" List_box would only list LINE layers.
When user selects Add Text the "Select Layer" List_box would change to show TEXT Layers or Text Style.
Then there would be a choice for selecting color of those objects before placing.

I've all of it working except the color part (not there yet) and the changing the list box contents
This snippet of code handles a text box opening or closing based on selection of a radio button On/Off

Code - Auto/Visual Lisp: [Select]
  1. (action_tile "radio_button_ON" "(mode_tile \"text_box_1\" 0)")
  2. (action_tile "radio_button_OFF" "(mode_tile \"text_box_1\" 1)")

Can this same approach be used for my needs?


J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

Tharwat

  • Swamp Rat
  • Posts: 523
  • Hypersensitive
Re: Radio_button controls and list boxes.
« Reply #1 on: February 14, 2020, 10:17:59 AM »
Hi,

Replace the correct keys that fits your used key names within your program.

Code - Auto/Visual Lisp: [Select]
  1. (setq layers '("Layer1" "layer2" "Layer3"))
  2. (setq styles '("Standard" "Arial" "Romans"))
  3.  
  4. (defun add:me (key lst)
  5.   )
  6.  
  7. (action_tile "Add_Line_Key" "(add:me \"List_Box_Key\" layers)")
  8. (action_tile "Add_Text_Key" "(add:me \"List_Box_Key\" styles)")
  9.  

jlogan02

  • Newt
  • Posts: 132
Re: Radio_button controls and list boxes.
« Reply #2 on: February 14, 2020, 10:37:21 AM »
Thanks Tharwat,

Nice website, by the way.

Hi,

Replace the correct keys that fits your used key names within your program.

Code - Auto/Visual Lisp: [Select]
  1. (setq layers '("Layer1" "layer2" "Layer3"))
  2. (setq styles '("Standard" "Arial" "Romans"))
  3.  
  4. (defun add:me (key lst)
  5.   )
  6.  
  7. (action_tile "Add_Line_Key" "(add:me \"List_Box_Key\" layers)")
  8. (action_tile "Add_Text_Key" "(add:me \"List_Box_Key\" styles)")
  9.  
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

Tharwat

  • Swamp Rat
  • Posts: 523
  • Hypersensitive
Re: Radio_button controls and list boxes.
« Reply #3 on: February 14, 2020, 10:42:23 AM »
Thanks Tharwat,
You're welcome anytime.

Nice website, by the way.

Thank you, that's too kind of you.

Rustabout

  • Mosquito
  • Posts: 17
Re: Radio_button controls and list boxes.
« Reply #4 on: February 14, 2020, 11:16:56 AM »
I think it can. You'd just add the "Start_List" and associated functions to the action_tiles. By default it will over-write the existing list.

I had a whirl at it, you can grab code off my files from wherever you might need it (I took a stab at the color part) - everything seems to be working but maybe not in a way you want it to. But you might pick up a tip or two at least.

jlogan02

  • Newt
  • Posts: 132
Re: Radio_button controls and list boxes.
« Reply #5 on: February 18, 2020, 08:34:44 PM »
Here's the code to this point.

Line/layer/color selection working.

Text/Layer/color selection working...How do I make the selected textstyle current?

I'm also doing something wrong with how I'm setting the list appearance. I want the Layer list and Style list to appear and disappear when each radio is selected. Ultimately the user would select the Add Text button and the styles list would be "current" in the same location as the layers list. Our text styles are equal to a layer so I should be able to say if L080 selected it goes on this layer. No need for a layer selection with text styles.
 
Code - Auto/Visual Lisp: [Select]
  1. ;;;--- Dialog Control Language - Part 7
  2.  
  3. ;;;--- Moved this line to the top to force all variables to be local
  4. (defun C:SAMPLE7()
  5.  
  6.  
  7. (defun saveVars()
  8.   (setq radios(get_tile "radios"))
  9.  
  10.   ;;;--- See if the user wants to save the settings
  11.   (setq saveSet(atoi(get_tile "saveset")))
  12.  
  13.   ;;;--- Get the selected item from the layer list
  14.   (setq sStr(get_tile "layerlist"))
  15.  
  16.   ;;;--- If the index of the selected item is not "" then something was selected
  17.   (if(/= sStr "")
  18.          (progn
  19.  
  20.       ;;;--- Something is selected, so convert from string to integer
  21.       (setq sIndex(atoi sStr))
  22.  
  23.  
  24.       ;;;--- And get the selected item from the list
  25.       (setq layerName(nth sIndex layerList))
  26.     )
  27.  
  28.     ;;;--- Else, nothing is selected
  29.     (progn
  30.  
  31.       ;;;--- Set the index number to -1
  32.       (setq sIndex -1)
  33.    
  34.       ;;;--- And set the name of the selected item to nil
  35.       (setq layerName nil)
  36.      )
  37.   )
  38.   )
  39.  
  40.   ;;;--- Main application
  41.  
  42.   ;;;--- Load the dcl file from disk into memory
  43.   (setq dcl_id (load_dialog "SAMPLE7x.dcl"))
  44.    
  45.  
  46.     ;;;--- Else, the DCL file was loaded
  47.     ;;(progn
  48.  
  49.       ;;;--- Load the definition inside the DCL file
  50.       (if (not (new_dialog "SAMPLE7x" dcl_id))
  51.         (progn
  52.           (alert "The SAMPLE7x definition was not found.")
  53.           (exit)
  54.         )
  55.                  )
  56.      
  57.         ;;;--- Else, the definition was loaded
  58.         (progn
  59.           (setq layerList(list "0" "LINE1" "LINE2" "LINE3" "LINE4" "LINE5"))
  60.           (setq StyleList(list "L080" "L100" "L120" "L140" "L175" "L200"));;Do I use this list to make the text style current?
  61.          
  62.  
  63.           ;;;--- Add the layer names to the dialog box
  64.           (start_list "layerlist" 3)
  65.           (mapcar 'add_list layerList)
  66.           (end_list)
  67.  
  68.                          (start_list "Stylelist" 3)
  69.           (mapcar 'add_list styleList)
  70.           (end_list)
  71.  
  72.            ;;;--- Add the code here to check for defaults
  73.           (if(/= (getvar "USERS1") "")
  74.             (progn
  75.               (setq radios (getvar "users1"))
  76.               (setq saveSet(getvar "users2"))
  77.               (setq layerIndex(getvar "users3"))
  78.                              (set_tile "radios" radios)
  79.               (set_tile "saveset" saveSet)
  80.               (set_tile "layerlist" layerIndex)
  81.             )
  82.           )
  83.  
  84.           ;;;--- If an action event occurs, do this function
  85.           (action_tile "line" "(setq action $value)")
  86.           (action_tile "text" "(setq action $value)")
  87.           (action_tile "cancel" "(done_dialog 1)")
  88.           (action_tile "accept" "(saveVars)(done_dialog 2)")
  89.  
  90.           ;;;--- Display the dialog box
  91.           (setq ddiag(start_dialog))
  92.  
  93.           ;;;--- Unload the dialog box
  94.           (unload_dialog dcl_id)
  95.  
  96.           ;;;--- If the cancel button was pressed - display message
  97.           (if (= ddiag 1)
  98.             (princ "\n \n ...SAMPLE7 Cancelled. \n ")
  99.           )
  100.  
  101.           ;;;--- If the "Okay" button was pressed
  102.           (if (= ddiag 2)
  103.             (progn
  104.  
  105.               ;;;--- Save the old layer and reset to new layer
  106.               (setq oldLay(getvar "clayer"))
  107.               (setvar "clayer" layerName)
  108.  
  109.               (if(= radios "line")
  110.                 (progn
  111.                         (setvar 'cecolor (rtos (acad_colordlg 256) 2 0))
  112.                                                         (command "line")
  113.                 )
  114.                                         )
  115.                 ;;;--- Else draw a polygon
  116.  
  117.              (if (= radios "text")
  118.                                   (progn
  119.                                                 (setvar 'cecolor (rtos (acad_colordlg 256) 2 0))
  120.                                            (command "text")
  121.                 )
  122.               )
  123.  
  124.               ;;;--- See if we need to save the settings
  125.               (if(= saveSet 1)
  126.                 (progn
  127.  
  128.                   ;;;--- Add code here to save the settings as defaults
  129.                   (setvar "USERS1" radios)
  130.                   (setvar "USERS2" (itoa saveSet))
  131.                   (setvar "USERS3" sSTR)
  132.                                          )
  133.               )
  134.             )
  135.           )
  136.         )
  137.  
  138.   ;;;--- Suppress the last echo for a clean exit
  139.   (princ)
  140.  
  141. )
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

Tharwat

  • Swamp Rat
  • Posts: 523
  • Hypersensitive
Re: Radio_button controls and list boxes.
« Reply #6 on: February 19, 2020, 11:55:12 AM »
Hi,
I have modified the codes and deleted the unnecessarily codes although you can return the savevars sub-function if you like and hopefully the following would work for you since that I did not test it due to the unavailability of the DCL codes. 

Code - Auto/Visual Lisp: [Select]
  1. (defun C:SAMPLE7 (/         *error*   table_    add:me    dcl_id
  2.                   ddiag     layerList StyleList rtn       clr
  3.                   vals
  4.                  )
  5.   (defun *error* (m)
  6.     (and dcl_id (<= dcl_id 0) (unload_dialog dcl_id))
  7.     (and vals (mapcar 'setvar '(cecolor clayer textstyle) vals))
  8.     (princ)
  9.   )
  10.   ;;                            ;;
  11.   (defun table_ (b / e n l)
  12.     (while (setq e (tblnext b (not e)))
  13.       (or (wcmatch (setq n (cdr (assoc 2 e))) "*|*")
  14.           (setq l (cons n l))
  15.       )
  16.     )
  17.     (acad_strlsort l)
  18.   )
  19.   ;;                            ;;
  20.   (defun add:me (key lst)
  21.     (start_list key)
  22.     (mapcar 'add_list lst)
  23.     (end_list)
  24.   )
  25.   ;;                            ;;
  26.   (cond
  27.     ((not (and (setq dcl_id (load_dialog "SAMPLE7x.dcl"))
  28.                (< 0 dcl_id)
  29.           )
  30.      )
  31.      (alert "Can't load main dialog <!>")
  32.     )
  33.     ((not (new_dialog "SAMPLE7x" dcl_id))
  34.      (princ "\nCan't start new dialog <!>")
  35.     )
  36.     (t
  37.      (setq layerList (table_ "LAYER")
  38.            styleList (table_ "STYLE")
  39.      )
  40.      (add:me "layerlist" layerList)
  41.      (add:me "Stylelist" styleList)
  42.      (action_tile "cancel" "(done_dialog 1)")
  43.      (action_tile
  44.        "accept"
  45.        "(setq rtn (mapcar 'get_tile '(\"line\" \"text\" \"layerlist\" \"Stylelist\")))
  46.                                 (done_dialog 2)"
  47.      )
  48. ;;;--- Display the dialog box
  49.      (setq ddiag (start_dialog))
  50. ;;;--- Unload the dialog box
  51.      (unload_dialog dcl_id)
  52. ;;;--- If the cancel button was pressed - display message
  53.      (cond
  54.        ((= ddiag 1) (princ "\n \n ...SAMPLE7 Cancelled. \n "))
  55.        ((and rtn
  56.              (= ddiag 2)
  57.              (setq vals (mapcar 'getvar '(cecolor clayer textstyle)))
  58.              (setq clr (acad_colordlg 256))
  59.              (setvar 'cecolor (itoa clr))
  60.         )
  61.         (cond ((= (car rtn) "1")
  62.                (setvar 'clayer (nth (atoi (caddr rtn)) layerlist))
  63.                (command "line")
  64.               )
  65.               ((= (cadr rtn) "1")
  66.                (setvar 'textstyle (nth (atoi (cadddr rtn)) stylelist))
  67.                (command "text")
  68.               )
  69.         )
  70.        )
  71.      )
  72.     )
  73.   )
  74.   (and vals (mapcar 'setvar '(cecolor clayer textstyle) vals))
  75.   (princ)
  76. )
  77.