Jump to content

Cleaner methods of user entry?


Akeane

Recommended Posts

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!

Link to comment
Share on other sites

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.

 

 

Multi radio 1.jpg

Edited by BIGAL
Link to comment
Share on other sites

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 by pkenewell
Added method to change the last default response
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...