×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

AutoLISP For Deleting Duplicates

AutoLISP For Deleting Duplicates

AutoLISP For Deleting Duplicates

(OP)
I have a drawing that is huge. This drawing came from another company and we are now maintaining it. The problem I have is that there seems to be thousands of duplicates on it. For example - there is a rectangle used to represent a sign - if you erase it you actually erase three or four of them. They are just piled on top of each other. I need to find a LISP that will allow me to select a group of enities and have any duplicates deleted. If anyone knows where I can find a program that will do this please let me know. I am running AutoCAD 14. Thanks!

RE: AutoLISP For Deleting Duplicates

;Command NODUPLICITY
;deletes duplicate copies of
;"LINE,LWPOLYLINE,CIRCLE,ARC,ELLIPSE,SPLINE"  elements in the drawing.
;POLYGONE, RECTANG AND PLINE are implictly included, being LWPOLYLINE type
;SELECT OBJECTS by any or all methods combined as usual, when prompted.
;I included BLOCKS in the last minutes.
;If 'has attributes', will be left in peace, even if duplicate.
;on request we may include a function to parse through the attributes
;and delete if all in all duplicate. This is pending
;I wrote this code today for you, so, I would appreciate DEBUG feedback
;and of course ideas to - simplify the code, and - to extend the functionality.

;tigrek@hotpop.com
;www.homescript.com

(defun C:NoDublicity()
(setq SUZY (ssget '((0 . "LINE,LWPOLYLINE,CIRCLE,ARC,ELLIPSE,SPLINE,INSERT"))))
(setq LENSUZY (sslength SUZY))
  (setq COUNTER 0)
  
     (setq SSLINE (ssadd))
     (setq SSLWPOLYLINE (ssadd))
     (setq SSCIRCLE (ssadd))
     (setq SSARC (ssadd))
     (setq SSELLIPSE (ssadd))
     (setq SSSPLINE (ssadd))
     (setq SSINSERT (ssadd))
  
  (while (setq EDNA (ssname SUZY COUNTER))
    (setq ED (entget EDNA))
  (cond
   ((= (dxf 0 ED) "LINE")     (ssadd EDNA SSLINE))
   ((= (dxf 0 ED) "LWPOLYLINE") (ssadd EDNA SSLWPOLYLINE))
   ((= (dxf 0 ED) "CIRCLE")     (ssadd EDNA SSCIRCLE))
   ((= (dxf 0 ED) "ARC")    (ssadd EDNA SSARC))
   ((= (dxf 0 ED) "ELLIPSE")    (ssadd EDNA SSELLIPSE))
   ((= (dxf 0 ED) "SPLINE")    (ssadd EDNA SSSPLINE))
   ((= (dxf 0 ED) "INSERT")    (if (not (ASSOC 66 ED))
                        (ssadd EDNA SSINSERT)
                )
   )
   (t nil)
  );END cond
    (setq COUNTER (+ 1 COUNTER))
  );END while

;GET THE FIRST LINE
;COMPARE TO LINES ONLY - IF ED LIST IDENTICAL, DELETE ONE OF THEM
    (setq SSWHICH SSLINE)  (purgeType)
    (setq SSWHICH SSLWPOLYLINE)  (purgeType)
    (setq SSWHICH SSCIRCLE)  (purgeType)
    (setq SSWHICH SSARC)  (purgeType)
    (setq SSWHICH SSELLIPSE)  (purgeType)
    (setq SSWHICH SSSPLINE)  (purgeType)
      (setq SSWHICH SSINSERT)  (purgeType)
)
;----------
(defun dxf (n ed) (cdr (assoc n ed)))
;-----------------
(defun purgeType()
(setq LENGTHSSWHICH (sslength SSWHICH))
;if identical list found, delete the original
 (if (> LENGTHSSWHICH 1)
   (progn
   (setq COUNTER 0)
     
   (while (setq EDNA (ssname  SSWHICH COUNTER))
        (print)(print "COUNTER ")(princ COUNTER)
      (print (dxf 0 ED))
      (setq ED (cddddr (entget EDNA)))
            (setq COUNTERNEXT 1)
            
        (while (setq EDNANEXT (ssname  SSWHICH (+ COUNTER COUNTERNEXT) ))
              (setq NAMY (dxf 0 (entget EDNANEXT)))
                (setq EDNEXT (cddddr (entget EDNANEXT)))
         ;compare lists ED and EDNEXT
         ;seemed like an involved recursive function would be needed here!
         ;then suddenly I had this inspiration - in one line of code
         ;tests if two lists are identical  -
         ;trick is,  to put the second list into a dummy list!!!
         ;and ask if the first list is member of the second list-list.
         ;what do you think?
              (if  (member ED (list EDNEXT))
          (progn
          (print "Duplicate ")(princ NAMY)
          (entdel EDNANEXT)
          (ssdel EDNANEXT SSWHICH)
        );END progn
          (PROGN
            (setq COUNTERNEXT (+ 1 COUNTERNEXT))
            )
          );END if   
            );END while
      ;(print ED)
        (setq COUNTER (+ 1 COUNTER))
    );END while
 ));END if
  (princ)
)
;-----------------

RE: AutoLISP For Deleting Duplicates

(OP)
Thanks so much for the routine!

RE: AutoLISP For Deleting Duplicates

most welcome.
I debugged on Acad2000 but had in mind Acad14 too.
So, I assume it worked there too.

RE: AutoLISP For Deleting Duplicates

(OP)
I haven't run into any problems with AutoCAD 14 as of yet. If I do I will be sure to let you know.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources