m4rdy Posted January 11, 2012 Posted January 11, 2012 Hi all, How can we find nearest specified Text/Mtext object from specified point? For example: I want to find nearest TB2A from point A. Thank you. mardi Quote
Lee Mac Posted January 11, 2012 Posted January 11, 2012 Quickly written: (defun NearestTextFromPoint ( pt str / d e i l m r s ) (if (setq s (ssget "_X" (list '(0 . "TEXT,MTEXT") (cons 1 str) (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) ) ) ) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) l (entget e) ) (if (< (setq d (distance pt (if (or (eq "MTEXT" (cdr (assoc 0 l))) (and (zerop (cdr (assoc 72 l))) (zerop (cdr (assoc 73 l))) ) ) (cdr (assoc 10 l)) (cdr (assoc 11 l)) ) ) ) (cond (m) ((1+ d))) ) (setq m d r e) r ) ) ) ) (defun c:test ( / s p ) (setq s (getstring t "\nString: ")) (if (setq p (getpoint "\nPoint: ")) (sssetfirst nil (ssadd (NearestTextFromPoint (trans p 1 0) s))) ) (princ) ) Quote
wimal Posted January 12, 2012 Posted January 12, 2012 Quickly written: I test it and working nicely Quote
Dadgad Posted January 12, 2012 Posted January 12, 2012 I test it and working nicely Faint praise for the code-meister. Perhaps a thank you might be in order? Quote
m4rdy Posted January 12, 2012 Author Posted January 12, 2012 Thank you Lee, It works for my quick tests. I am stilll studying your routine.... mardi Quote
orange Posted June 8, 2015 Posted June 8, 2015 sorry for replying to an old thread. I need this too, but after selecting a point, got this error: "Point: ; error: bad argument type: lentityp nil" Quote
Lee Mac Posted June 8, 2015 Posted June 8, 2015 sorry for replying to an old thread. I need this too, but after selecting a point, got this error: "Point: ; error: bad argument type: lentityp nil" Change: (defun c:test ( / s p ) (setq s (getstring t "\nString: ")) (if (setq p (getpoint "\nPoint: ")) (sssetfirst nil (ssadd (NearestTextFromPoint (trans p 1 0) s))) ) (princ) ) to: (defun c:test ( / e s p ) (setq s (getstring t "\nString: ")) (if (setq p (getpoint "\nPoint: ")) (if (setq e (NearestTextFromPoint (trans p 1 0) s)) (sssetfirst nil (ssadd e)) (princ (strcat "\nNo text/mtext with content \"" s "\" found in the current layout.")) ) ) (princ) ) 1 Quote
orange Posted June 8, 2015 Posted June 8, 2015 (edited) thanks Lee, that works great! um, could you please modify it so that it finds any nearest text? edit: never mind, it works with wildcard. Edited June 8, 2015 by orange 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.