Jump to content

Help - Select duplicate entities


teknomatika

Recommended Posts

Hi I need help from masters of LISP to a routine.

When I use the "overkill" command in Autocad, duplicate entities are deleted. Now, i want to a similar routine, which detects duplicate entities, but instead of deleting them, may be possible to save them in a selection or, as would be desirable to relate to a new layer.

As my knowledge is basic, I do not know how to solve. I appreciate the help.

Link to comment
Share on other sites

  • Replies 72
  • Created
  • Last Reply

Top Posters In This Topic

  • teknomatika

    28

  • pBe

    18

  • ReMark

    10

  • David Bethel

    8

Top Posters In This Topic

Posted Images

So you are looking for a utility that will move all duplicate entities to another layer rather than delete them, right?

 

ReMark, Yes, that's it.

I want to take duplicate entities, to give them a specific use.

Link to comment
Share on other sites

depending on what you mean by 'entity' you might be able to accomplish this through the filter command

 

Daniel:Any and all AutoCAD entities: lines, polylines, arcs, circles, points, text, etc..

For what I want, it would be good to consider at least the lines.

With the command filter, do not seem to select only those entities duplicate.

Link to comment
Share on other sites

This would be require a comparison routine using lists, a lot of list, but i think its doable

 

It gives me headache just by thinking about it :)

 

What about this approach

limited testing..

 

(defun c:test  (/ objs i entN ent LineColl Entcoll LstR DupSS)
     (if (not (tblsearch "LAYER" "Duplicates"))
           (entmake
                 (list (cons 0 "LAYER")
                       (cons 100 "AcDbSymbolTableRecord")
                       (cons 100 "AcDbLayerTableRecord")
                       (cons 2 "Duplicates")
                       (cons 62 2)
                       (cons 70 0)))
           )
    [color=blue](setq objs (ssget '((0 . "*LINE,ARC,CIRCLE"))))[/color]
[color=blue]     (repeat (setq i (sslength objs))[/color]
[color=blue]           (setq entN (ssname objs (setq i (1- i))))[/color]
[color=blue]           (setq ent (entget entN))[/color]
[color=blue]           (foreach[/color]
[color=blue]                  itm  '(-1 5 330 62)[/color]
[color=blue]                 (setq ent (vl-remove (assoc (eval itm) ent) ent)))[/color]
[color=blue]           (setq LineColl (cons ent LineColl)[/color]
[color=blue]                 EntColl  (cons (list ent entN) Entcoll)))[/color]
[color=blue]     (setq DupSS (ssadd)[/color]
[color=blue]           lnt   (length LineColl))[/color]
[color=blue]     (while (setq a (car LineColl))[/color]
[color=blue]           (setq b        (cons a b)[/color]
[color=blue]                 LineColl (vl-remove a (cdr LineColl)))[/color]
[color=blue]           (if (/= lnt (length LineColl))[/color]
[color=blue]                 (setq Dupss[/color]
[color=blue]                            (ssadd (cadr (setq LstR (assoc a entcoll)))[/color]
[color=blue]                                   DupSS))[/color]
[color=blue]                 (setq lnt (length LineColl))[/color]
[color=blue]                 )[/color]
[color=blue]           )[/color]
     (command
           "_chprop"
           objs
           "R"
           Dupss
           ""
           "p"
           "Layer"
           "Duplicates"
           "")
     )

 

The line enitites are exact duplicates, granting all entity properties are "BYLAYER"

 

EDIT: after further testing, as it turned out it works for other entities as well... after seeing David's code i tried including arcs/polylines and circles in the selection...

Edited by pBe
Link to comment
Share on other sites

Here could be the basic engine:

 

[b][color=BLACK]([/color][/b]defun c:finddup [b][color=FUCHSIA]([/color][/b]/ ss dl en ed[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]defun remove [b][color=NAVY]([/color][/b]expr lst[b][color=NAVY])[/color][/b][color=#8b4513];;;TonyT or VNesterowski[/color]
   [b][color=NAVY]([/color][/b]apply 'append [b][color=MAROON]([/color][/b]subst nil [b][color=GREEN]([/color][/b]list expr[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]mapcar 'list lst[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]foreach e '[b][color=NAVY]([/color][/b][color=#2f4f4f]"ARC"[/color] [color=#2f4f4f]"CIRCLE"[/color] [color=#2f4f4f]"LINE"[/color] [color=#2f4f4f]"POINT"[/color] [color=#2f4f4f]"SOLID"[/color] [color=#2f4f4f]"TRACE"[/color][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]princ [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nSearching "[/color] e [color=#2f4f4f]"s\n"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 0 e[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
          [b][color=MAROON]([/color][/b]progn
            [b][color=GREEN]([/color][/b]set [b][color=BLUE]([/color][/b]read [b][color=RED]([/color][/b]strcat [color=#2f4f4f]"S"[/color] e[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]ssadd[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
            [b][color=GREEN]([/color][/b]setq dl nil[b][color=GREEN])[/color][/b]
            [b][color=GREEN]([/color][/b]while [b][color=BLUE]([/color][/b]setq en [b][color=RED]([/color][/b]ssname ss 0[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]princ [color=#2f4f4f]"\r"[/color][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]prin1 en[b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]setq ed [b][color=RED]([/color][/b]entget en[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]foreach g '[b][color=RED]([/color][/b]-1 5[b][color=RED])[/color][/b]
                       [b][color=RED]([/color][/b]setq ed [b][color=PURPLE]([/color][/b]remove [b][color=TEAL]([/color][/b]assoc g ed[b][color=TEAL])[/color][/b] ed[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]if [b][color=RED]([/color][/b]member ed dl[b][color=RED])[/color][/b]
                       [b][color=RED]([/color][/b]ssadd en [b][color=PURPLE]([/color][/b]eval [b][color=TEAL]([/color][/b]read [b][color=OLIVE]([/color][/b]strcat [color=#2f4f4f]"S"[/color] e[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                       [b][color=RED]([/color][/b]setq dl [b][color=PURPLE]([/color][/b]cons ed dl[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                   [b][color=BLUE]([/color][/b]ssdel en ss[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

Each entity type would have it's own selection set ie SLINE for lines SARC for arcs etc

 

You could probably add MTEXT LWPOLYLINE and a few other entity types. Heavy POLYLINEs and INSERTs with ATTRIButes would not work.

 

 

This will get very very slow on large drawings. -David

Link to comment
Share on other sites

Here could be the basic engine:

 

Brilliant David, I had the same general idea but cant quite make the removal as efficient as yours

 

BTW: This...

(defun remove (expr lst);;;TonyT or VNesterowski

(apply 'append (subst nil (list expr) (mapcar 'list lst))))

 

:thumbsup:

Link to comment
Share on other sites

This adds some of the other types

 

[b][color=BLACK]([/color][/b]defun c:finddup [b][color=FUCHSIA]([/color][/b]/ ss dl en ed[b][color=FUCHSIA])[/color][/b]
                                                                 
 [b][color=FUCHSIA]([/color][/b]defun remove [b][color=NAVY]([/color][/b]expr lst[b][color=NAVY])[/color][/b]                                        [color=#8b4513];;;REMOVE AN EXPRESSION FROM A LIST[/color]
   [b][color=NAVY]([/color][/b]apply 'append [b][color=MAROON]([/color][/b]subst nil [b][color=GREEN]([/color][/b]list expr[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]mapcar 'list lst[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]   [color=#8b4513];;;TonyT or VNesterowski[/color]

 [b][color=FUCHSIA]([/color][/b]foreach e '[b][color=NAVY]([/color][/b][color=#2f4f4f]"3DFACE"[/color] [color=#2f4f4f]"ARC"[/color] [color=#2f4f4f]"ATTDEF"[/color] [color=#2f4f4f]"CIRCLE"[/color] [color=#2f4f4f]"LINE"[/color] [color=#2f4f4f]"POINT"[/color]    [color=#8b4513];;;FOREACH SIMPLE ENTITY TYPE[/color]
              [color=#2f4f4f]"SHAPE"[/color] [color=#2f4f4f]"SOLID"[/color] [color=#2f4f4f]"TRACE"[/color] [color=#2f4f4f]"TEXT"[/color] [color=#2f4f4f]"MTEXT"[/color] [color=#2f4f4f]"LWPOLYLINE"[/color] [color=#2f4f4f]"ELLIPSE"[/color][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]princ [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nSearching "[/color] e [color=#2f4f4f]"s\n"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]                    [color=#8b4513];;;DISPLAY ENTITY TYPE[/color]
      [b][color=NAVY]([/color][/b]setq dl nil[b][color=NAVY])[/color][/b]                                              [color=#8b4513];;;MAKE AN EMPTY COMPARISON LIST[/color]
      [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 0 e[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]               [color=#8b4513];;;SEARCH FOR THIS ENTITY TYPE[/color]
           [b][color=MAROON]([/color][/b]set [b][color=GREEN]([/color][/b]read [b][color=BLUE]([/color][/b]strcat [color=#2f4f4f]"S"[/color] e[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]ssadd[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]                   [color=#8b4513];;;MAKE A UNIQUE PICKSET FOR EACH ENTITY TYPE[/color]
           [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]setq en [b][color=BLUE]([/color][/b]ssname ss 0[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]                        [color=#8b4513];;;GET THE INITIAL PICKSET ENAME[/color]
                  [b][color=GREEN]([/color][/b]princ [color=#2f4f4f]"\r"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]prin1 en[b][color=GREEN])[/color][/b]                        [color=#8b4513];;;PROGRESS DISPLAY[/color]
                  [b][color=GREEN]([/color][/b]setq ed [b][color=BLUE]([/color][/b]entget en[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]                          [color=#8b4513];;;GET THE ENTITY DEFINITION[/color]
                  [b][color=GREEN]([/color][/b]foreach g '[b][color=BLUE]([/color][/b]-1 5[b][color=BLUE])[/color][/b]                             [color=#8b4513];;;REMOVE THE ENAME[/color]
                      [b][color=BLUE]([/color][/b]setq ed [b][color=RED]([/color][/b]remove [b][color=PURPLE]([/color][/b]assoc g ed[b][color=PURPLE])[/color][/b] ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]        [color=#8b4513];;;AND HANDLE DATA[/color]
                  [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]member ed dl[b][color=BLUE])[/color][/b]                             [color=#8b4513];;;IF THE ENTITY DEFINITION IS A MEMBER OF THE COMPASSION LIST[/color]
                      [b][color=BLUE]([/color][/b]ssadd en [b][color=RED]([/color][/b]eval [b][color=PURPLE]([/color][/b]read [b][color=TEAL]([/color][/b]strcat [color=#2f4f4f]"S"[/color] e[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]    [color=#8b4513];;;THEN ADD THE ENTITY TO THE DUPLICATE SET[/color]
                      [b][color=BLUE]([/color][/b]setq dl [b][color=RED]([/color][/b]cons ed dl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]                    [color=#8b4513];;;ELSE ADD THE DEFINITION TO THE COMPARISON LIST[/color]
                  [b][color=GREEN]([/color][/b]ssdel en ss[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]                               [color=#8b4513];;;REMOVE THE CURRENT INITIAL PICKSET ENAME[/color]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]                                                        [color=#8b4513];;;EXIT CLEAN[/color]
[color=#8b4513];;;DUPLICATE PICKSET NAMES ARE GLOBAL  ie  SLINE   SARC    SCIRCLE[/color]

 

 

pBe, Thanks Just out of curiosity, why would you remove groups 330 and 62?

 

-David

Edited by David Bethel
Link to comment
Share on other sites

pBe, Thanks Just out of curiosity, why would you remove groups 330 and 62?

-David

 

Oh that.. forgot to remove it while testing the code, trying to exclude entities with assigned color, same thing for 330, forgot to remove that as well while testing for attached image and xref, but its apparent that theres no need for that too. :)

Link to comment
Share on other sites

Dear friends: It certainly is a routine that could be improved, but for now is to solve what I wanted.

However, in certain situations, does not seem to work. After calling the routine and selected entities, the layer "duplicates" is created but it gives an error function. Annex clip of the message.

I forgot to tell: In this error condition, the layer is created but duplicate entities are not detected.

What is the reason?

 

message_error.jpg

Link to comment
Share on other sites

Strange.. the code is not even supposed to invoke the Layer command. whee did that come from?

 

EDIT: I see now, it gives that error if none found :lol: (the code doesnt include much errorr trapping in testing phase) perhaps enitites on locked layer?

 

Quick Fix:

 

 
[color=sienna](setq objs (ssget ":L" '((0 . "*LINE,ARC,CIRCLE"))))[/color]
....
[color=sienna](if (> (sslength Dupss) 1)[/color]
[color=sienna](command "_chprop"  objs "R" Dupss  "" "p" "Layer" "Duplicates" "") (princ "\nNo Duplicates Found:"))[/color]
[color=sienna](princ)[/color]
[color=sienna]   )[/color]

 

 

You can add this to David's Code

 

(ssdel en ss)) 
[color=blue](if (setq i (sslength (setq objs (eval (read (strcat "S" e))))))[/color]
[color=blue](repeat i[/color]
[color=blue]         (setq ent_e (entget (ssname objs (setq i (1- i)))))[/color]
[color=blue]                 (entmod (subst (cons 8 (strcat "Dup_" e))(assoc 8 ent_e) ent_e))[/color]
[color=blue]                      )[/color]
[color=blue]        )[/color]
           ))                              
 (prin1))        

 

It will create a layer for every Type of Entity Found i.e. If duplicate lines are found it will create

Dup_LINES layer and so on..

 

Hope this helps

Edited by pBe
Link to comment
Share on other sites

Thank you for your attention.

I could not tell what the situation is that the routine fails.

Apparently has to do with the different layers that belong to entities.

pBe, I tried but could not merge the code. It did not work. I appreciate that you do.

Link to comment
Share on other sites

(defun c:finddup (/ ss dl en ed)

 (defun remove (expr lst)                                        ;;;REMOVE AN EXPRESSION FROM A LIST
   (apply 'append (subst nil (list expr) (mapcar 'list lst))))   ;;;TonyT or VNesterowski
 (foreach e '("3DFACE" "ARC" "ATTDEF" "CIRCLE" "LINE" "POINT"    ;;;FOREACH SIMPLE ENTITY TYPE
              "SHAPE" "SOLID" "TRACE" "TEXT" "MTEXT" "LWPOLYLINE" "ELLIPSE")
      (princ (strcat "\nSearching " e "s\n"))                    ;;;DISPLAY ENTITY TYPE
      (setq dl nil)                                              ;;;MAKE AN EMPTY COMPARISON LIST
      (and (setq ss (ssget "X" (list (cons 0 e))))               ;;;SEARCH FOR THIS ENTITY TYPE
           (set (read (strcat "S" e)) (ssadd))                   ;;;MAKE A UNIQUE PICKSET FOR EACH ENTITY TYPE
           (while (setq en (ssname ss 0))                        ;;;GET THE INITIAL PICKSET ENAME
                  (princ "\r") (prin1 en)                        ;;;PROGRESS DISPLAY
                  (setq ed (entget en))                          ;;;GET THE ENTITY DEFINITION
                  (foreach g '(-1 5)                             ;;;REMOVE THE ENAME
                      (setq ed (remove (assoc g ed) ed)))        ;;;AND HANDLE DATA
                  (if (member ed dl)                             ;;;IF THE ENTITY DEFINITION IS A MEMBER OF THE COMPASSION LIST
                      (ssadd en (eval (read (strcat "S" e))))    ;;;THEN ADD THE ENTITY TO THE DUPLICATE SET
                      (setq dl (cons ed dl)))                    ;;;ELSE ADD THE DEFINITION TO THE COMPARISON LIST
                  (ssdel en ss))
           ([color=blue]if (setq i (sslength (setq objs (eval (read (strcat "S" e))))))[/color]
[color=blue]  (repeat i[/color]
[color=blue]                (setq ent_e (entget (ssname objs (setq i (1- i)))))[/color]
[color=blue]                        (entmod (subst (cons 8 (strcat "Dup_" e))(assoc 8 ent_e) ent_e))[/color]
[color=blue]                             )[/color]
[color=blue]               )[/color]
[color=blue]           ))      [/color]                         ;;;REMOVE THE CURRENT INITIAL PICKSET ENAME
 (prin1)) 

 

I added the code to Davids's 2nd post. I'm pretty sure his modification would be a lot elegant that that. so for now you can used that as is, until David updates his post (no disrespect D :))

Link to comment
Share on other sites

pBe, Thanks - you're fine. It's refreshing to see someone give proper credit on coding.

 

[b][color=BLACK]([/color][/b]defun c:makedupl [b][color=FUCHSIA]([/color][/b]/ ss dl en ed ef[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]defun remove [b][color=NAVY]([/color][/b]expr lst[b][color=NAVY])[/color][/b]                                        [color=#8b4513];;;REMOVE AN EXPRESSION FROM A LIST[/color]
   [b][color=NAVY]([/color][/b]apply 'append [b][color=MAROON]([/color][/b]subst nil [b][color=GREEN]([/color][/b]list expr[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]mapcar 'list lst[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]   [color=#8b4513];;;TonyT or VNesterowski[/color]

 [b][color=FUCHSIA]([/color][/b]foreach e '[b][color=NAVY]([/color][/b][color=#2f4f4f]"3DFACE"[/color] [color=#2f4f4f]"ARC"[/color] [color=#2f4f4f]"ATTDEF"[/color] [color=#2f4f4f]"CIRCLE"[/color] [color=#2f4f4f]"LINE"[/color] [color=#2f4f4f]"POINT"[/color]    [color=#8b4513];;;FOREACH SIMPLE ENTITY TYPE[/color]
              [color=#2f4f4f]"SHAPE"[/color] [color=#2f4f4f]"SOLID"[/color] [color=#2f4f4f]"TRACE"[/color] [color=#2f4f4f]"TEXT"[/color] [color=#2f4f4f]"MTEXT"[/color] [color=#2f4f4f]"LWPOLYLINE"[/color] [color=#2f4f4f]"ELLIPSE"[/color][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]princ [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nSearching "[/color] e [color=#2f4f4f]"s\n"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]                    [color=#8b4513];;;DISPLAY ENTITY TYPE[/color]
      [b][color=NAVY]([/color][/b]setq dl nil[b][color=NAVY])[/color][/b]                                              [color=#8b4513];;;MAKE AN EMPTY COMPARISON LIST[/color]
      [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 0 e[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]               [color=#8b4513];;;SEARCH FOR THIS ENTITY TYPE[/color]
           [b][color=MAROON]([/color][/b]set [b][color=GREEN]([/color][/b]read [b][color=BLUE]([/color][/b]strcat [color=#2f4f4f]"S"[/color] e[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]ssadd[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]                   [color=#8b4513];;;MAKE A UNIQUE PICKSET FOR EACH ENTITY TYPE[/color]
           [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]setq en [b][color=BLUE]([/color][/b]ssname ss 0[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]                        [color=#8b4513];;;GET THE INITIAL PICKSET ENAME[/color]
                  [b][color=GREEN]([/color][/b]princ [color=#2f4f4f]"\r"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]prin1 en[b][color=GREEN])[/color][/b]                        [color=#8b4513];;;PROGRESS DISPLAY[/color]
                  [b][color=GREEN]([/color][/b]setq ed [b][color=BLUE]([/color][/b]entget en[b][color=BLUE])[/color][/b] ef ed[b][color=GREEN])[/color][/b]                    [color=#8b4513];;;GET THE ENTITY DEFINITION[/color]
                  [b][color=GREEN]([/color][/b]foreach g '[b][color=BLUE]([/color][/b]-1 5[b][color=BLUE])[/color][/b]                             [color=#8b4513];;;REMOVE THE ENAME[/color]
                      [b][color=BLUE]([/color][/b]setq ef [b][color=RED]([/color][/b]remove [b][color=PURPLE]([/color][/b]assoc g ef[b][color=PURPLE])[/color][/b] ef[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]        [color=#8b4513];;;AND HANDLE DATA[/color]
                  [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]member ef dl[b][color=BLUE])[/color][/b]                             [color=#8b4513];;;IF THE ENTITY DEFINITION IS A MEMBER OF THE COMPASSION LIST[/color]
                      [b][color=BLUE]([/color][/b]progn                                     [color=#8b4513];;;THEN[/color]
                        [b][color=RED]([/color][/b]ssadd en [b][color=PURPLE]([/color][/b]eval [b][color=TEAL]([/color][/b]read [b][color=OLIVE]([/color][/b]strcat [color=#2f4f4f]"S"[/color] e[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]  [color=#8b4513];;;ADD THE ENTITY TO THE DUPLICATE SET[/color]
                        [b][color=RED]([/color][/b]entmod [b][color=PURPLE]([/color][/b]subst [b][color=TEAL]([/color][/b]cons 8 [b][color=OLIVE]([/color][/b]strcat [color=#2f4f4f]"DUP_"[/color] e[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][color=#8b4513];;;AND[/color]
                                       [b][color=TEAL]([/color][/b]assoc 8 ed[b][color=TEAL])[/color][/b] ed[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]        [color=#8b4513];;;CHANGE IT'S LAYER[/color]
                      [b][color=BLUE]([/color][/b]setq dl [b][color=RED]([/color][/b]cons ef dl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]                    [color=#8b4513];;;ELSE ADD THE DEFINITION TO THE COMPARISON SET[/color]
                  [b][color=GREEN]([/color][/b]ssdel en ss[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]                               [color=#8b4513];;;REMOVE THE CURRENT INITIAL PICKSET ENAME[/color]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]                                                        [color=#8b4513];;;EXIT CLEAN[/color]

 

I still like the PICKSET approach, but I made the change with each individual entity.

 

Again this will be a very slow run time routine on large drawings.. -David

Link to comment
Share on other sites

[quote name='David Bethel;425414

]pBe' date=' Thanks - you're fine. It's refreshing to see someone give proper credit on coding.

[/quote']

 

You're welcome David cheers :beer:

Link to comment
Share on other sites

pBe and David:

OK. Works.

However, if the entities belong to different layers, no longer works.

The differentiation into layers by different entities, it is interesting. However, in my case is irrelevant. Could be aggregated in the same layer.

In this context, I appreciate if you can get the routine work even considering that the entities may be duplicated in different layers and these with different colors.

Best explaining my definition of duplicate entities applies to entities with similar characteristics but may belong to different layers and, therefore, with different colors.

I hope my bad English does not become confused the issue.

Link to comment
Share on other sites

You mean an exclusion list? There are times that duplicate layers or Lintypes or colors are valid? and there are times that they're not?

Or it would always be that way? geometry duplicates regardless of Layers/LT/Colors?

 

Problem I can see with that is, which one the two will be moved to "Duplicaetes" layer?

 

Anyhoo.. Try this

(defun c:test  (/ lvn objs entN ent OrgEnt ObjColl a Entcoll LstR dupobj ln nl ln)
     (vl-load-com)
     [color=blue](setq objs (ssget ":L" '((0 . "~VIEWPORT") (0 . "~INSERT")(8 . "~*_D"))))[/color]
     (repeat [color=blue](sslength objs)[/color]
           (setq entN [color=blue](ssname objs 0))[/color]
           (setq OrgEnt (cons entN OrgEnt))
           (setq ent (entget entN))
           (foreach
                  itm
                     '[color=blue](-1 5 8 62 6)[/color]
                 (setq ent (vl-remove (assoc (eval itm) ent) ent)))
           (setq ObjColl (cons ent ObjColl)
                 EntColl (cons (list ent entN) Entcoll))
           (ssdel entN objs))
     (while (setq a (car ObjColl))
  [color=blue](if ( member a (cdr ObjColl))[/color]
[color=blue]                     (progn[/color]
[color=blue]             (setq ObjColl (vl-remove a (cdr ObjColl)))[/color]
[color=blue]                       (setq dupobj (entget (car (member[/color]
[color=blue]                                                   (setq LstR (cadr (assoc a  entcoll)))[/color]
[color=blue]                                                   OrgEnt))))[/color]
[color=blue]                       (entmod (subst (cons 8 (setq NL (strcat (cdr[/color]
[color=blue]                                                                     (setq ln (assoc 8 dupobj))) "_D")))[/color]
[color=blue]                                   (assoc 8 dupobj)  dupobj))[/color]
[color=blue]                       (if (not (member NL lvn))[/color]
[color=blue]                           (progn[/color]
[color=blue]                             (vla-put-color (vlax-ename->vla-object (tblobjname "LAYER" NL))[/color]
[color=blue]                                  (cdr (assoc 62 (tblsearch "LAYER" (cdr ln)))))[/color]
[color=blue]                                     (setq lvn (cons NL lvn))))[/color]
[color=blue]                       )[/color]
                (setq ObjColl (cdr ObjColl)))
                  (prompt "\r\\")
           (princ LstR)
           (prompt "\t......Evaluating....please wait.. ")
           (princ)
           )
     (princ)
     )

 

 

Warning: Adverse effect on Anotative TEXT/MTEXT

Edited by pBe
Link to comment
Share on other sites

pBe,

With the update is happening the following: The routine detects and locates in its own layer duplicate entities, but entities existing in the global design and that are not duplicated. Another definition for duplicate entities that I consider is the fact that they are overlapping each other. These are but overlapping entities duplicate what I intend to be differentiated.

On the other hand, the routine operates on the entire design. I intend to do so only in relation to elements within a selection.

Attached with a picture for better understanding.

Basically, I have two drawings with each other which have different geometric entities and equals geometric entities.

When I overlap the two drawings, I want the routine to select and isolate layer itself, these common entities (duplicate).

 

pBe,

By the way, the Text and Mtext entities, have no relevance to what I want.

 

I appreciate the attention being paid to the issue.

 

duplicates_example.jpg

Link to comment
Share on other sites

pBe,

With the update is happening the following: The routine detects and locates in its own layer duplicate entities, but entities existing in the global design and that are not duplicated. Another definition for duplicate entities that I consider is the fact that they are overlapping each other. These are but overlapping entities duplicate what I intend to be differentiated.

 

Hence the statement

"Problem I can see with that is, which one the two will be moved to "Duplicates" layer?"

On the other hand, the routine operates on the entire design. I intend to do so only in relation to elements within a selection.

 

Change:

(setq objs (ssget "_X" '((0 . "~VIEWPORT") (0 . "~INSERT"))))

to:

(setq objs (ssget ":L" '((0 . "~VIEWPORT") (0 . "~INSERT"))))

By the way, the Text and Mtext entities, have no relevance to what I want.

Its a warning for other users to be aware of the effect.

 

Basically, I have two drawings with each other which have different geometric entities and equals geometric entities.

When I overlap the two drawings, I want the routine to select and isolate layer itself, these common entities (duplicate).

 

How'd you propose to go about doing that?

We could include a prompt to select an entity for layer information and retain enitities on that layer. and the rest would be moved to a new layer with the its original name with a suffix of _D?

 

Would that work for you?

 

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...