Hello Everyone 🙂
Im trying to implement Lee's selection prompt but can't get it to work (see code below). Please help.....
(defun c:PROCMAIN1 () (initget "Alpha Beta Gamma") (if (= "Alpha" (getkword "\nChoose [Alpha/Beta/Gamma]: ")) (c:Alpha) (= "Beta" (getkword "\nChoose [Alpha/Beta/Gamma]: ")) (c:Beta) (= "Gamma" (getkword "\nChoose [Alpha/Beta/Gamma]: ")) (c:Gamma) ) (princ) )
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
In order to use (initget) only once, you would need to set a variable with the User's choice in it, and then work with what they chose. It could be done with separate (if) tests, but in a situation like this with more than two possibilities, the (cond) function is the best way to go. Something like:
(defun c:PROCMAIN1 (/ choice)
(initget "Alpha Beta Gamma")
(setq choice (getkword "\nChoose [Alpha/Beta/Gamma]: "))
(cond
((= choice "Alpha") (c:Alpha))
((= choice "Beta") (c:Beta))
((= choice "Gamma") (c:Gamma))
)
(princ)
)
Or, since the option words are the same as the command names, this shorter version also works:
(defun c:PROCMAIN1 (/ choice)
(initget "Alpha Beta Gamma")
(setq choice (getkword "\nChoose [Alpha/Beta/Gamma]: "))
(eval (read (strcat "(C:" choice ")")))
(princ)
)
EDIT: Also consider doing this, to force the User to make one of those choices by forbidding Enter:
....
(initget 1 "Alpha Beta Gamma")
....