Duplicate object removal

Discussion in 'AutoCAD' started by dyarza, Jul 21, 2003.

  1. dyarza

    dyarza Guest

    Hi all,

    Does anybody have a routine that will delete any duplicate objects in a drawing? By that I mean two identical polylines on the same layer for example.

    Thanks,

    David
     
    dyarza, Jul 21, 2003
    #1
  2. dyarza

    Murph Guest

    The overkill command in the express tools or if you have MAP Mapcleanup command(s).



     



    Murph



     



    "dyarza" <> wrote in message news:...

    Hi all,

    Does anybody have a routine that will delete any duplicate objects in a drawing? By that I mean two identical polylines on the same layer for example.

    Thanks,

    David
     
    Murph, Jul 21, 2003
    #2
  3. dyarza

    Odie Silva Guest

    As far as I know, Map cleanup will not find text or blocks.



    If you want to search for duplicate blocks and text I wrote



    a routine to take care of that.



    Just let me know



     



    Odie



    "Murph" <> wrote in message news:...



    The overkill command in the express tools or if you have MAP Mapcleanup command(s).



     



    Murph



     



    "dyarza" <> wrote in message news:...

    Hi all,

    Does anybody have a routine that will delete any duplicate objects in a drawing? By that I mean two identical polylines on the same layer for example.

    Thanks,

    David
     
    Odie Silva, Jul 21, 2003
    #3
  4. dyarza

    dyarza Guest

    Odie,

    I do have text and blocks that I would want to find and remove. If you have any input in a routine that would do that it would be greatly appreciated.

    David.

     
    dyarza, Jul 21, 2003
    #4
  5. dyarza

    Huw Guest

    Huw, Jul 22, 2003
    #5
  6. dyarza

    martin Guest

    I have checked the (remdup.lisp) it seems sometimes to remove blocks that
    are not duplicate.
    martin


    ----------------------------------------------------------------------------
    ----


    ;REMDUP.LSP - Removes duplicated blocks belonging to the same group name
    ;
    ;Code by: Odie Silva
    ;Written in February 2003 - Note: Improved version will provide dialog for
    ; tolerance input.
    (defun c:remdup (/ cntdup cnt cntc obj_name object_namec sslen sslec)
    (setvar "cmdecho" 0)
    (vl-load-com)
    (setq app (vlax-get-acad-object))
    (setq doc (vla-get-activedocument app))
    (setq mspace (vla-get-modelspace doc))
    (vla-startundomark doc)
    (vla-ZoomExtents app)
    (Princ "\nSelecting All Blocks...\n")
    (setq ss (ssget "x" '((0 . "INSERT"))))
    (setq sslen (sslength ss))
    (setq cnt 0)
    (setq cntdup 0)
    (princ (strcat (rtos sslen 2 0) " blocks found!"))
    (while (< cnt sslen)
    (setq obj (vlax-ename->vla-object (ssname ss cnt)))
    (if (and
    (not obj)
    (< cnt sslen)
    )
    (setq cnt (1+ cnt))
    (progn
    (setq obj_insertion (vla-get-insertionpoint obj))
    ;;; (vla-ZoomCenter
    ;;; app
    ;;; obj_insertion
    ;;; (vlax-make-variant 10 vlax-vbDouble); this will force to zoom into
    ;;; ); ; element being processed
    (setq
    sa (vlax-safearray->list (vlax-variant-value obj_insertion))
    )
    (setq obj_name (vla-get-name obj))
    (if (/= obj_name "ADCADD_ZZ")
    (progn
    (setq wpt1 (polar sa (cvunit 45 "degree" "radians") 15))
    (setq wpt2 (polar sa (cvunit 225 "degree" "radians") 15))
    (setq ssc (ssget "c" wpt1 wpt2 '((0 . "INSERT"))))
    (if ssc
    (progn
    (setq cntc 0)
    (setq sslenc (sslength ssc))
    (if (> sslenc 1)
    (progn
    (while (/= cntc sslenc)
    (setq
    objc
    (vlax-ename->vla-object (ssname ssc cntc))
    )
    (setq obj_insertionc
    (vla-get-insertionpoint objc)
    )
    (setq sac (vlax-safearray->list
    (vlax-variant-value obj_insertionc)
    )
    )

    (setq obj_namec (vla-get-name objc))
    (setq dist (distance sa sac))
    (if (and
    (= (vla-get-name obj) (vla-get-name objc))
    (/= (vla-get-objectid obj)
    (vla-get-objectid objc)
    )
    (<= dist 0.1)
    )
    (progn
    (vla-delete objc)
    (setq cntdup (1+ cntdup))
    )
    )
    (setq cntc (1+ cntc))
    )
    ) ;end of progn
    ) ;end of if
    ) ;end of progn
    ) ;end of if
    ) ;end of progn
    ) ;end of if
    ) ;end of progn
    ) ;end of if
    (setq cnt (1+ cnt))
    ) ;end of while
    (vla-ZoomPrevious app)
    (alert (strcat (rtos cnt 2 0)
    " blocks processed!"
    "
    \n"
    (rtos cntdup 2 0)
    " blocks deleted!"
    )
    )
    (vla-endundomark doc)
    (princ)
    ) ;end of defun















    ----------------------------------------------------------------------------
    ----


    ;REMDUPTXT.LSP - Removes duplicated texts
    ;
    ;Code by: Odie Silva
    ;Written in February 2003 - Note: Improved version will provide dialog for
    ; tolerance input.(defun c:remduptext (/
    cntdup cnt cntc obj_name object_namec sslen sslec)
    (setvar "cmdecho" 0)
    (vl-load-com)
    (setq app (vlax-get-acad-object))
    (setq doc (vla-get-activedocument app))
    (setq mspace (vla-get-modelspace doc))
    (vla-startundomark doc)
    (vla-ZoomExtents app)
    (Princ "\nSelecting All Text...\n")
    (setq ss (ssget "x" '((0 . "TEXT"))))
    (setq sslen (sslength ss))
    (setq cnt 0)
    (setq cntdup 0)
    (princ (strcat (rtos sslen 2 0) " text found!"))
    (while (< cnt sslen)
    (setq obj (vlax-ename->vla-object (ssname ss cnt)))
    (if (and
    (not obj)
    (< cnt sslen)
    )
    (setq cnt (1+ cnt))
    (progn
    (setq sa (vlax-safearray->list
    (vlax-variant-value
    (vla-get-insertionpoint obj)
    )
    )
    )
    (setq obj_name (vla-get-textstring obj))
    (setq wpt1 (polar sa (cvunit 45 "degree" "radians") 15))
    (setq wpt2 (polar sa (cvunit 225 "degree" "radians") 15))
    (setq ssc (ssget "c" wpt1 wpt2 '((0 . "text"))))
    (if ssc
    (progn
    (setq cntc 0)
    (setq sslenc (sslength ssc))
    (if (> sslenc 1)
    (progn
    (while (/= cntc sslenc)
    (setq
    objc
    (vlax-ename->vla-object (ssname ssc cntc))
    )
    (setq sac (vlax-safearray->list
    (vlax-variant-value
    (vla-get-insertionpoint objc)
    )
    )
    )
    (setq obj_namec (vla-get-textstring objc))
    (setq dist (distance sa sac))
    (if (and
    (= (vla-get-textstring obj)
    (vla-get-textstring objc)
    )
    (/= (vla-get-objectid obj)
    (vla-get-objectid objc)
    )
    (<= dist 0.1)
    )
    (progn
    (vla-delete objc)
    (setq cntdup (1+ cntdup))
    )
    )
    (setq cntc (1+ cntc))
    )
    )
    )
    )
    )
    ) ;end of progn
    )
    (setq cnt (1+ cnt))
    ) ;end of while
    (vla-ZoomPrevious app)
    (alert (strcat (rtos cnt 2 0)
    " text processed!"
    "
    \n"
    (rtos cntdup 2 0)
    " text deleted!"
    )
    )
    (vla-endundomark doc)
    (princ)
    )
     
    martin, Aug 4, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.