Akeane Posted October 22, 2020 Posted October 22, 2020 I have a few methods of getting user entry, but i was wondering if theres a cleaner way to do it that guarantees correct entry? A special preference goes to methods that remember the users entry and defaults to that value in the case of no entry A couple methods i have are: (if (not autoName) (setq autoName "N")) (setq autoName_choice (substr (strcase (getstring (strcat "Auto label lines? (Y/N) (" autoName "):"))) 1 1) (if (= autoName_choice "") (print (strcat "Bad or no user entry. " autoName " is default")) (setq autoName autoname_choice) ) (setq fixedDir (substr (strcase (getstring "\n(OR)tho/(NS)/(EW)/(Dy)namic Design offset?") ) 1 2) ) ;capitalises and takes first 2 letters (cond ((= fixedDir "OR") (prompt "Orthogonal mode selected")) ((= fixedDir "EW") (prompt "EW mode selected")) ((= fixedDir "NS") (prompt "NS mode selected")) ((= fixedDir "DY") (prompt "Dynamic mode selected")) (T (progn (prompt "bad user entry, Dynamic is default") (setq fixedDir "DY") ) ) ) (while (not (setq input1 (getreal "enter some number"))) ;note "not" only works on reals, "" is still a vailid string (prompt "no number entered, please try again") ) Or would love to know what other methods there are that guarantees correct input, next option would be to create a lisp that takes a message and the acceptable inputs and prompts the user until it fits the acceptable input style Cheers! Quote
David Bethel Posted October 22, 2020 Posted October 22, 2020 Have you looked into (getkword) used in conjunction with (initget) ? -David 1 Quote
tombu Posted October 22, 2020 Posted October 22, 2020 Best explanation and examples of GETKWORD are from Lee Mac: http://www.lee-mac.com/promptwithdefault.html 1 Quote
BIGAL Posted October 22, 2020 Posted October 22, 2020 (edited) Look in downloads for Multi radio buttons.lsp its a library routine use in any code and replaces initget. The prompts are user definable. Defaults can be set and changes saved for repeat use. RLX has some nice dcl options as well. Edited October 22, 2020 by BIGAL Quote
pkenewell Posted October 22, 2020 Posted October 22, 2020 (edited) Note: When using (initget) and (getkword), the way you format the prompt can help make your options clean and control whether a context menu is available for the prompt: Note this format (done with variables just for clarity): (setq prm "Select the Following Options" ; Prompt to display. opt "[Yes/No/Maybe/Cancel]" ; options to display NOTE - they must match initget, be enclosed in [] and have forward slashes! Then AutoCAD will make ; context menu. def (if def def "Yes") ) (initget "Yes No Maybe Cancel") ; Keyword Options - Capital letter will be the Nmenomic selection. (if (and (/= (setq resp (getkword (strcat "\n" prm " " opt " <" def ">: "))) def)(/= resp nil)) (setq def resp) ) Edited October 23, 2020 by pkenewell Added method to change the last default response Quote
Akeane Posted October 22, 2020 Author Posted October 22, 2020 Hey guys this has been real big help, had never heard of initget and getkword before. Ill do some more research on this, and write bck Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.