Take a look at this approach.
This is an example only & needs more error checking and does not
address metric.
I reduced the number of key strokes by using a get key routine.
At the command line enter rb the space bar then press a key L, D or H
You are the prompted for the size. Here you could also allow the letter M
to switch to metric.
Better yet would be a dialog box.
;; enter rb and spacebar or enter to run
(defun C:RB (/ otm llyr plw ansx dia dod fr)
(setq otm (getvar "orthomode"))
(setq llyr (getvar "clayer"))
(setq plw (getvar "plinewid"))
(setq ansx (get_key "LDH" "Press key [L D or H] Line, Donut or Hook? : "))
(if (not ansx)
(exit) ; user quit
)
(initget 7)
(setq dia (getdist "\nEnter rebar size : "))
;; need size error checking
(setvar "clayer" "0")
(command "orthomode" "1")
(cond
((= ansx "L")
(command "plinewid" dia)
(command "pline")
(while (> (getvar "cmdactive") 0) (command pause))
)
((= ansx "D")
(setq did (getvar "donutid"))
(setq dod (getvar "donutod"))
(command "donut" "0" dia)
(while (> (getvar "cmdactive") 0) (command pause))
(setvar "donutid" did)
(setvar "donutod" dod)
)
((= ansx "H")
(command "plinewid" dia)
(command "pline")
(while (> (getvar "cmdactive") 0) (command pause))
(setq fr (getvar "filletrad"))
(setvar "filletrad" (* dia 2))
(command "fillet" "p" "last")
(command "filletrad" fr)
)
) ; end cond stmt
(setvar "clayer" llyr)
(setvar "plinewid" plw)
(command "orthomode" otm)
(princ)
)
(prompt "\nEnter rb and spacebar or enter to run.")
(princ)
;;--------------------------------------------------------
;; get a key press, return only if matches filter
;; return nil if Enter is pressed
(defun get_key (keys msg / key KeyCode Lp)
(setq keys (append (vl-string->list (strcase keys))
(vl-string->list (strcase keys t))
)
)
(setq Lp t)
(while Lp ; Main Loop
(prompt (strcat "\n" msg))
(setq Key nil)
(while (= Key nil) ; Loop here until a key is pressed
(setq Key (grread nil 2)) ; get a key press
)
;; Process the key press
(if (= (car key) 2) ; Skip if not a KeyPress
(progn
(setq KeyCode (cadr Key)) ; Set ASCII Key Code
(cond
((= KeyCode 13) ; ENTER key pressed
(setq KeyCode nil
Lp nil) ; Exit Loop
)
((member KeyCode keys) ; got a hit
(setq Lp nil) ; Exit Loop
)
) ; end cond stmt
) ; progn
) ; Endif
) ;End While
(if keyCode
(strcase (chr keyCode))
)
) ; end defun