Author Topic: Delete duplicate blocks from drawing  (Read 3035 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
Delete duplicate blocks from drawing
« on: April 21, 2010, 12:40:17 PM »
Hey,

I have looked online but have not found what I'm looking for so I came here to see if anyone has written something like this. Basically I have a bunch of blocks in a drawing and I need to delete all of the duplicates leaving me only with blocks that have unique names. Can someone help me with this? Thanks

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Delete duplicate blocks from drawing
« Reply #1 on: April 21, 2010, 12:55:08 PM »
I'd try something like this:

Code: [Select]
(defun c:eblock (/ i ss en bn bl)
  (and (setq i -1
            ss (ssget "X" '((0 . "INSERT"))))
       (while (setq en (ssname ss (setq i (1+ i))))
              (setq bn (cdr (assoc 2 (entget en))))
              (if (not (member bn bl))
                  (setq bl (cons bn bl))
                  (entdel en))))
  (prin1))

Totally untested.  -David
R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Delete duplicate blocks from drawing
« Reply #2 on: April 21, 2010, 01:40:48 PM »
I would think you may want to:

Select Inserts to keep
Build a list of block names
ssget all inserts with those name
remove the keepers from the selection set
then entdel the remaining
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.