; Multi button Dialog box for a single choice repalcment of initget
; By Alan H Feb 2019

; Example code as the radio button click will close the default button setting is required 
; if you have defined a default setting

; (if (not AH:Butts)(load "Multi radio buttons.lsp")) 			; loads the program if not loaded already
; (if (= but nil)(setq but 1)) 						; this is needed to set default button
									; you can reset default button to user pick
; (setq ans (ah:butts but "V"   '("Please choose" "Blank sheet" "File" "OTHER"))) 	; ans holds the button picked value as a string
									; if you want ans a number use (atof ans) or (atoi ans)

; (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
; (if (= but nil)(setq but 1))
; (setq ans (ah:butts but "h"  '("Flipped or not "Flipped" "No Flip"))) ; ans holds the button picked value


; (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
; (if (= but nil)(setq but 1))
; (setq ans (ah:butts but "H" '("Choose " "Block" "Point" ))) ; ans holds the button picked as an integer value

(vl-load-com)
(defun AH:Butts (AHdef verhor butlst / fo fname x  k )


(defun butval ( / l)
(setq x 1)
(repeat (length butlst)
    (setq l (strcat "Rb" (rtos x 2 0)))
    (if  (= (get_tile l) "1" )
        (setq but x)
    )
    (setq x (+ x 1))
)
(princ but)
)

; (setq fo (open (setq fname "D:\\acadtemp\\yesno.dcl") "w"))
(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line  "AHbutts : dialog 	{" fo)
(write-line  (strcat "	label =" (chr 34) (nth 0 butlst) (chr 34) " ;" )fo)
(write-line "	: row	{" fo)
(if (=  (strcase verhor) "V")
(progn
(write-line "	: boxed_radio_column 	{" fo)
(write-line  (strcat " width = " (rtos (+ (strlen (nth 0 butlst)) 10) 2 0) " ;")  fo)		; increase 10 if label does not appear
)
(write-line "	: boxed_radio_row	{" fo)
)
(setq x 1)
(repeat (- (length butlst) 1) 
(write-line "	: radio_button	{" fo)
(write-line  (strcat "key = "  (chr 34) "Rb" (rtos x 2 0)  (chr 34) ";") fo)
(write-line  (strcat "label = " (chr 34) (nth x  butlst) (chr 34) ";") fo)
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
(setq x (+ x 1))
)
(write-line "	}" fo)
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
(write-line "	ok_cancel;" fo)
(write-line "	}" fo)
(close fo)
(setq dcl_id (load_dialog fname))
(if (not (new_dialog "AHbutts" dcl_id) )
(exit)
)
(setq x 1)
(repeat (- (length butlst) 1)
(setq k (strcat "Rb" (rtos x 2 0)))
(if (= ahdef x)(set_tile k "1"))
(setq x (+ x 1))
)


(action_tile "accept" "(butval)(done_dialog)")
(action_tile "cancel" "(done_dialog)(exit)")
(start_dialog)
(unload_dialog dcl_id)
;(vl-file-delete fname)
(if (= but nil)(setq but 2))
(nth but butlst)
)

