TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ELOQUINTET on April 21, 2010, 12:40:17 PM

Title: Delete duplicate blocks from drawing
Post by: ELOQUINTET 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
Title: Re: Delete duplicate blocks from drawing
Post by: David Bethel 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
Title: Re: Delete duplicate blocks from drawing
Post by: CAB 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