Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

DUPLICATE ENTITIES REMOVAL LISP? 1

Status
Not open for further replies.

11echo

Petroleum
Jun 4, 2002
444
...Long time ago I got involved with a drawing that had multiple entities for the same thing. Somebody had xref'd in or wblock the same thing in multiple times and this was on a large drawing file. The computer tech back then coughed up a LISP routine that looked at the start/stop pt.s and when it found multiple entities with the same point it would remove them ...worked slick! Well fast forward 8 yr.s & 3 jobs later, and I find myself with the same problem ...except on a VERY large drawing, and for the life of me I can't remember the name of the LISP routine! ...Can anybody help me here? ...OR introduce me to another way (or LISP) to eliminate these extra entities!!?? THX! ...Mark
 
Replies continue below

Recommended for you

Assuming you have Express Tools installed-

use the OVERKILL command.
 
OVERKILL works well but if you don't have Express Tools try this :
Code:
;Tip1744:  CLEAR.LSP        Clear duplicates      (c)2001, ;Andrzej Gumula

(defun DXF (A) (cdr (assoc A (entget ONE)))) ;end dxf

(defun COMPLEX  ()
  (while (not (wcmatch (DXF 0) "*END*"))
    (setq ONE  (entnext ONE)
          ELEM (append ELEM (list ONE)))
    (CHECK)) ;end while
  ) ;end complex

(defun CORECT  (A)
  (cond ((= (type (cdr A)) 'list)
         (cons (car A) (mapcar '(lambda (X) (atof (rtos X 2 8))) (cdr A))))
        ((member (type (cdr A)) (list 'INT 'REAL))
         (cons (car A) (mapcar '(lambda (X) (atof (rtos X 2 8))) (list (cdr A)))))
        (t A))) ;end corect

(defun CHECK  ()
  (foreach X  (entget ONE)
    (if (not (member (car X) '(-2 -1 5 6 8 62 100)))
      (setq TEMP (cons (CORECT X) TEMP))))) ;end check

 ;(defun c:clear (/  CM LISTA NEW ONE TEMP OLD ZNACZNIK)
(defun C:CLEAR  ()
  (setq CM    (getvar "cmdecho")
        LISTA NIL
        NEW   NIL
        ONE   NIL
        TEMP  NIL
        OLD   (ssget "_X"))
  (setvar "cmdecho" 0)
  (cond
    (OLD
     (command "_-layer" "_u" "*" "")
     (prompt "\nDrawing clearing. ")
     (prompt "\nPlease wait... \n")
     (while (cond (ONE (setq ONE (entnext ONE)))
                  (t (setq ONE (entnext))))
       (setq ELEM (append ELEM (list ONE)))
       (CHECK)
       (if (or (and (= (DXF 0) "INSERT") (= (DXF 66) '1)) (= (DXF 0) "POLYLINE"))
         (COMPLEX))
       (if (member TEMP LISTA)
         (foreach X ELEM (entdel X)))
       (setq LISTA (cons TEMP LISTA)
             TEMP  NIL
             ELEM  NIL)
       (cond (ZNACZNIK (setq ZNACZNIK NIL) (princ "\r\\"))
             (t (setq ZNACZNIK (princ "\r/"))))) ;end while
     (prompt (strcat "\nNumber of elements before clearing- " (itoa (sslength OLD))))
     (prompt
       (strcat "\nNumber of elements after clearing- " (itoa (sslength (ssget "_X"))))))
    (t (prompt "\nFound zero elements. "))) ;end cond
  (setvar "cmdecho" CM)
  (princ)) ;end file
(prompt "\nLoaded new command CLEAR. ")
(princ)

____________________
Acad2005, Terramodel
 
Hey I want to thank both CarlB & lpseifert for the helpful advice here! I did have AutoCAD 2006 express tools but never knew of the "overkill" command ...till now. I tried that command on my drawing but it was so large it was grinding for some time before I had to escape from it. Then I tried lpseifert's Lisp routine, it's more basic and not as "harsh" ...When it's finished, then I try the overkill command to polish the drawing file. THX again!!! ...Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor