Emmanuel Delay Posted July 13, 2022 Posted July 13, 2022 (edited) I need to select a object that holds a text. But sometimes that object is missing, then I want to type a value. Is there an elegant way to do this? So a user input expects either an object selection (nentsel) of a (getstring) ? I can do something like this: then I click on nothing and then get to type something, but that's not the elegant user experience (if (null (setq obj_sel (nentsel))) (setq get_str (getstring "\nEnter text: ")) ) Edit: is INITGET one of the things I should look at? Edited July 13, 2022 by Emmanuel Delay Quote
marko_ribar Posted July 13, 2022 Posted July 13, 2022 (edited) You want to EDIT text where it exist by click, or store typing to some variable like "get_str" ? Or you want to type text, store it in variable like "get_str" and mod. text of entity by click on it, if and only if it is textually editable ? If second option, you can always hit ENTER to get "" with (getstring) and avoid click-ing if not valid entity... Maybe : (defun c:foo ( / get_str obj-sel dxf ) (setq get_str (getstring t "\nEnter text : ")) (if (and (/= get_str "") (snvalid get_str) (setq obj_sel (car (nentsel "\nPick object..."))) (setq dxf (vl-some (function (lambda ( x ) (if (eq (type (cdr x)) 'str) x) )) (vl-remove-if (function (lambda ( y ) (vl-position (car y) (list 0 5 100)) )) (entget obj_sel) ) ) ) ) (entupd (cdr (assoc -1 (entmod (subst (cons (car dxf) get_str) dxf (entget obj_sel)))))) ) (princ) ) Edited July 13, 2022 by marko_ribar Quote
Emmanuel Delay Posted July 13, 2022 Author Posted July 13, 2022 I want to read data that's on a dwg, from old plans. Then extract that data, so as to (half automatically) generate blocks with filled in attributes in the new dwg, with new blocks ... That's the easy part. My specific problem is just this simple task of getting a user input that's either a nentsel or a getstring. And not have to first press enter (empty string) before being asked to click on an object ... or vice versa. One user input that accepts either. Quote
marko_ribar Posted July 13, 2022 Posted July 13, 2022 Yes, I see... Try (initget 128) before nentsel... It will accept strings too... 1 Quote
Emmanuel Delay Posted July 13, 2022 Author Posted July 13, 2022 Okay, I'll take that. My example works for preset strings (like Y / N) , but for now that's okay (defun c:test (/ str obj) (initget 128 "Y y N n .") (setq str (nentsel "\nSelect TEXT,MTEXT,ATTDEF or type Y/N: ")) (if (or (= str "Y") (= str "y") (= str "N") (= str "n") (= str ".")) (progn ;; do stuff here ) (if (setq obj (car str)) (setq str (cdr (assoc 1 (entget obj)))) ) ) (princ str) (princ ) ) Quote
mhupp Posted July 13, 2022 Posted July 13, 2022 (edited) 8 hours ago, Emmanuel Delay said: Is there an elegant way to do this? So a user input expects either an object selection (nentsel) of a (getstring) ? (if (null (setq obj_sel (nentsel))) (setq get_str (getstring "\nEnter text: ")) ) defaults to selecting text. Will only ask for input if you don't select anything. (right click / enter) (or (setq obj_sel (nentsel "\nSelect Text [Enter for user input]: ")) (setq get_str (getstring "\nEnter text: "))) Edited July 13, 2022 by mhupp 1 Quote
Steven P Posted July 13, 2022 Posted July 13, 2022 So I have this but.. it will only work I think with an initget - might be handy. I thought I could take out the initget but that wasn't working for me. This one gets a point, think you can also do it with nentsel Could do it "select text or -enter- (or whatever) to enter text", which is a long way round to do what you did above (defun c:testthis ( / ) (setvar "errno" 0) (while (/= 52 (getvar "errno")) (initget "M D S H") (setq result (getpoint "\nPick a point: ")) (cond ((= 'list (type result)) (setq insertpoint result)(setvar "errno" 52) ) ((= "M" (strcase result)) (progn (setq MorDor "M")(setvar "errno" 52)) ) ((= "D" (strcase result)) (setq MorDor "D") ) ((= "S" (strcase result)) (setq gridspacing (getreal "Enter Grid Spacing:")) ) ((= "H" (strcase result)) (setq textheight (getreal "Enter Text Height:")) ) (t (setvar "errno" 52)) ) ; end cond ) ;end while (princ result) ) 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.