CAB, Ronjonp,
Your programs may have problems if the Text has justification other than 'Left' or if any of the objects are drawn in a plane not parallel to the WCS plane.
This could be another way to approach it:
(defun c:test ( / di en in ls p1 pt s1 s2 tl )
(setq di 600.0)
(if
(and
(setq s1 (ssget "_X" (list '(0 . "TEXT,MTEXT") (cons 410 (getvar 'CTAB)))))
(setq s2 (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'CTAB)))))
)
(progn
(repeat (setq in (sslength s1))
(setq en (entget (ssname s1 (setq in (1- in)))))
(setq pt
(cdr
(assoc
(if
(or (eq "MTEXT" (cdr (assoc 0 en)))
(and
(zerop (cdr (assoc 72 en)))
(zerop (cdr (assoc 73 en)))
)
)
10 11
)
en
)
)
)
(if (eq "TEXT" (cdr (assoc 0 en)))
(setq pt (trans pt (cdr (assoc -1 en)) 0))
)
(setq tl (cons (list (car pt) (cadr pt)) tl))
)
(repeat (setq in (sslength s2))
(setq en (ssname s2 (setq in (1- in)))
pt (trans (cdr (assoc 10 (entget en))) en 0)
pt (list (car pt) (cadr pt))
ls tl
)
(while (and (setq p1 (car ls)) (not (<= (distance pt p1) di)))
(setq ls (cdr ls))
)
(if (null ls) (entdel en))
)
)
)
(princ)
)
The while loop could be replaced with a vl-some / vl-every, but I didn't want to use Visual for the sake of one function...