Author Topic: [SOLVED] Delete Blocks with no Text Near Them  (Read 5045 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: [SOLVED] Delete Blocks with no Text Near Them
« Reply #15 on: September 16, 2011, 10:28:36 PM »
Yes it can be done.
in order to refine the process a set of rules must be developed to guide the routine to make the correct selections.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: [SOLVED] Delete Blocks with no Text Near Them
« Reply #16 on: September 17, 2011, 09:58:09 AM »
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:

Code: [Select]
(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...

ronjonp

  • Needs a day job
  • Posts: 7528
Re: [SOLVED] Delete Blocks with no Text Near Them
« Reply #17 on: September 17, 2011, 12:37:17 PM »
Nice solution Lee  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: [SOLVED] Delete Blocks with no Text Near Them
« Reply #18 on: September 17, 2011, 12:41:37 PM »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: [SOLVED] Delete Blocks with no Text Near Them
« Reply #19 on: September 17, 2011, 01:00:59 PM »
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.

No attempt was made to make it other than WCS, but I thought dxf 10 was never an obscure point. Therefore the "close enough' applied. After all without using a bounding box using dxf 11 can still be off.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.