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

menu selection issue lisp

1 REPLY 1
Reply
Message 1 of 2
bart_van_tuyl
226 Views, 1 Reply

menu selection issue lisp

Hi,

 

I am custom to making menu slevtions in Autolisp ussing the following method

 

			(setq MYCHOICE (strcase(getstring (strcat "\nWelkom " (getvar "loginname") ". Kies een menu-optie: [<Item 1>/<Item 2>/<Item 3>/<Item 4>]: "))))
			(if (or (equal MYCHOICE "ITEM 1"))(SUBCOMMAND1))
			(if (or (equal MYCHOICE "ITEM 2"))(SUBCOMMAND2))
			(if (or (equal MYCHOICE "ITEM 3"))(SUBCOMMAND3))
			(if (or (equal MYCHOICE "ITEM 4"))(SUBCOMMAND4)).....

 Nice but this only works if I type out the menu choice in full if I click I get "I", which is a right royal pain seeing as the options all start with "I

 

 

how do I overcome this?

1 REPLY 1
Message 2 of 2
Kent1Cooper
in reply to: bart_van_tuyl

Can you omit the word "Item" and the space in each, and just use the numbers?  Put Item into the prompt wording, and let the options be <1/2/3/4>.  That would also eliminate the need for the (strcase) function.

 

You can use (initget) and (getkword) instead of (getstring) to limit the User's input, so that it will ask again if they don't give a valid option.  And you can use (cond) instead of a series of (if) functions, so that it will stop looking as soon as it finds the chosen option.

 

[By the way, those (or) functions are not doing anything for you.  And in the case of a text string, you can use the shorter (=) instead of (equal).]

 

I may not have the re-wording right, since I don't know the language, but....

 

(initget "1 2 3 4")

(setq MYCHOICE (getkword (strcat "\nWelkom " (getvar "loginname") ". Kies een menu-optie Item: [<1/2/3/4>]: ")))
(cond

  ((= MYCHOICE "1") (SUBCOMMAND1))

  ((= MYCHOICE "2") (SUBCOMMAND2))

  ((= MYCHOICE "3") (SUBCOMMAND3))

....

); cond

Kent Cooper, AIA

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

Post to forums  

Autodesk Design & Make Report

”Boost