I am looking for some code that would allow me to select a MTEXT Entity - or other entity - (as the DEFAULT option) but also to allow me to type in some text manually or to pick a point in the drawing. Something that would present the user with:
"Select an object or [P to pick a point]" or
"Select MTEXT or [M to type].
I can write some code to type in text manually as the default option and get the second option to select entity using getstring and then write some condition of if code but I don't know how to do it having entsel as default opion.
Any help would be appreciated. Thank you.
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
For fixed options, you can use an initget / getkword combination - here is a quick example:
(defun c:test ( / sel str ) (while (null str) (setvar 'errno 0) (initget "Type Exit") (setq sel (entsel "\nSelect MText [Type/Exit] <Exit>: ")) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (or (null sel) (= "Exit" sel)) (setq str "") ) ( (= "Type" sel) (setq str (getstring t "\nEnter text <Exit>: ")) ) ( (/= "MTEXT" (cdr (assoc 0 (entget (car sel))))) (princ "\nThat isn't MText.") ) ( (setq str (cdr (assoc 1 (entget (car sel)))))) ) ) (if (/= "" str) (princ (strcat "\nUser input: " str)) ) (princ) )
For more information on this technique, you may wish to read my tutorial on Prompting with a Default Option.
For arbitrary text input during object selection, see my 'Selection or Text' function, posted here.
Lee
You're welcome - ask if you are unsure of anything.
Lee