; Multi toggle Dialog box for multi choice 
; By Alan H Oct 2019

; Example code 
; (if (not AH:Toggs)(load "Multiple toggles.lsp"))
; (setq ans (reverse (ah:toggs   '("Yes or No" "Yes" "No"))))

; (if (not AH:Toggs)(load "Multiple toggles.lsp"))
; (setq ans (reverse (ah:toggs   '("Choose objject type" "Line" "Circle" "Pline" "Arc" "Hatch" "Other"))))

; (if (not AH:Toggs)(load "Multiple toggles.lsp"))
; (setq ans (reverse  (ah:toggs '("Choose kneeholes " "Cupboard 1" "Cupboard 2" "Cupboard 3" "Cupboard 4" "Cupboard 5"))))


(vl-load-com)
(defun AH:Toggs (ahbutlst / fo fname x  y keylst keynum v_lst dcl_id)

(defun mkv_lst ( / )
  (setq v_lst '())
  (setq x 1)
  (repeat (- (length ahbutlst) 1)
    (setq val (strcat "Tb" (rtos x 2 0)))
    (setq v_lst (cons (get_tile val) v_lst))
    (setq x (+ x 1))
  )
)

(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line  "AHtoggles : dialog 	{" fo)
(write-line  (strcat "	label =" (chr 34) (nth 0 ahbutlst) (chr 34) " ;" )fo)
(write-line "	: column	{" fo)
(write-line  " width =30 ;" fo )
(setq x 1)
(repeat (- (length ahbutlst) 1) 
  (write-line "	: toggle	{" fo)
  (write-line "alignment = left ;"  fo)
  (write-line  (strcat "key = "  (chr 34) "Tb" (rtos x 2 0)  (chr 34) ";") fo)
  (write-line  (strcat "label = " (chr 34) (nth x  ahbutlst) (chr 34) ";") fo)
  (write-line "	}" fo)
  (write-line "spacer_1 ;" fo)
  (setq x (+ x 1))
)
(write-line "spacer_1 ;" fo)
(write-line "	ok_cancel;" fo)
(write-line "	}" fo)
(write-line "	}" fo)
(close fo)

(setq dcl_id (load_dialog fname))
(if (not (new_dialog "AHtoggles" dcl_id) )
(exit)
)

(setq y 0)
(repeat (- (length ahbutlst) 1)
    (setq keynum (strcat "Tb" (rtos (setq y (+ Y 1)) 2 0)))
    (set_tile keynum "0")
   (mode_tile keynum 3)
)

(action_tile "accept" "(mkv_lst)(done_dialog)")

(action_tile "cancel" "(done_dialog)")
(start_dialog)
(unload_dialog dcl_id)
(vl-file-delete fname)
(princ v_lst)
)

