Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selection Prompt in command line

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
JCprog
357 Views, 4 Replies

Selection Prompt in command line

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)
)

 

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: JCprog

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")

....

Kent Cooper, AIA
Message 3 of 5
_Tharwat
in reply to: JCprog

Read about COND function

Message 4 of 5
JCprog
in reply to: Kent1Cooper

Thanks you much Kent! Works flawlessly Smiley Very Happy

Message 5 of 5
JCprog
in reply to: _Tharwat

Thanks for your reply Tharwat.....I will look into it 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost