Just putting this up here as something I wanted for a while and had 10 minutes to think last night.
I'd been wanting a routine "Select an entity or enter a value". Been doing it with initget which gives discrete values and not every possibility. So made up the following.
All good so far, haven't found out where it is broken yet.
Just to get your brains working then, trying to figure out how to change the mouse pointer as it hovers over an entity and not select it? Using grread and it's options you either get mouse pointer change and it selects automatically or no mouse pointer change and select with a mouse click as far as I can see. Any ideas?
Thanks
(defun c:EntOrValue ( / msg MyResult)
(setq msg "\nSelect an Entity or enter a value: \n")
(setq MyResult (EntorValue msg)
) ; end defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun EntorValue ( MSG / EndLoop sel MyEnt MyValue enta entb pt)
(setq MyValue "")
(setq MyEnt (list))
(setq EndLoop "No")
(princ MSG)
(while (= EndLoop "No") ; start loop
(setq sel (nth 1 (grread nil 0 2))) ; read keyboard / mouse inputs. Ignore mouse position, only if clicked
(if (= (type sel) 'LIST)
(progn ; if sel is a LIST,... ie. a mouse click, a point returned
(setq MyEnt (nentselp sel)) ; select entity from point
(if (= nil MyEnt)
(Princ "\nMissed! Try again. Select text or enter a value: ") ; entity not selected
(setq EndLoop "Yes") ; entity selected, end while loop
) ; end if
) ; end progn
(progn ; if sel is not a LIST, i.e. a single keyboard entry
(if (or (and (> sel 47)(< sel 57))(= sel 46)) ; numbers only
(progn
(princ (chr sel))
(setq MyValue (strcat MyValue (chr sel) ))
)
)
(if (= sel 45) ; -ve ; make negative number
(progn
(setq MyValue (strcat (chr sel) MyValue ))
(princ " Making -ve\n")(princ MyValue)
) ; end progn
) ; end if
(if (= sel 13) ; enter - end number input, end loop
(progn
(setq EndLoop "Yes")
) ; end progn
) ; end if
) ; end progn
) ; end if list
) ; end while
(if ( = (length MyEnt) 0) ; if entity not selected
(progn
MyValue ; return number entered
) ; end progn
(progn
;;GetEnt code
(setq enta (car MyEnt))
(setq pt (cdr (assoc 10 (entget enta))) )
;;fix for nenset or entsel requirements
(setq entb (last (last (nentselp pt)))) ;; use sel?
(if (and (/= entb nil) (/= (type entb) 'real) )
(progn
(if (wcmatch (cdr (assoc 0 (entget entb))) "ACAD_TABLE,*DIMENSION,*LEADER")(setq enta entb))
)
)
(setq MyEnt enta)
MyEnt ; return entity name, including nested say text from dimensions
) ; end progn
) ; end if
)