Author Topic: Delete duplicate blocks in a drawing  (Read 4726 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
Delete duplicate blocks in a drawing
« on: October 20, 2015, 05:08:10 PM »
Hello,

I asked a similar question in the following post but this routine is not working for nested or anonymous blocks that are generated when dynamic parameters are adjusted.
Has anyone written a similar routine that will erase duplicate blocks to include nested and anonymous blocks?

http://www.theswamp.org/index.php?topic=33111.msg385530#msg385530

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Delete duplicate blocks in a drawing
« Reply #1 on: October 22, 2015, 07:32:21 AM »
Sorry, I don't know much about dynamic blocks.  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Delete duplicate blocks in a drawing
« Reply #2 on: October 22, 2015, 07:47:04 AM »
What do you mean by 'duplicate blocks'?

More than one reference of a block definition?
Duplicate block definitions with the same geometry?

ELOQUINTET

  • Guest
Re: Delete duplicate blocks in a drawing
« Reply #3 on: October 28, 2015, 11:16:36 AM »
Sorry if I'm not providing all of the information but I am doing so intentionally because why we are trying to do this is not relevant. We are essentially trying to isolate blocks with unique attribute values by erasing blocks with the same information in the tags from the drawing. I hope this clarifies what is needed a bit more. Thanks

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Delete duplicate blocks in a drawing
« Reply #4 on: October 28, 2015, 01:36:27 PM »
Sorry if I'm not providing all of the information but I am doing so intentionally because why we are trying to do this is not relevant.

I was not asking the 'why', but rather 'what do you consider to be a duplicate block'.

We are essentially trying to isolate blocks with unique attribute values by erasing blocks with the same information in the tags from the drawing.

OK, so only duplicate in the sense that they hold the same attribute values.

If two or more duplicates are detected, how should the program decide which references to erase? Or does it not matter?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Delete duplicate blocks in a drawing
« Reply #5 on: October 28, 2015, 02:19:59 PM »
Is the OP referring to dynamic properties or attribute values? It seems the terms are, incorrectly, used interchangeably.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Delete duplicate blocks in a drawing
« Reply #6 on: October 28, 2015, 02:26:59 PM »
Assuming attributes, here's a rough start:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ddb ( / a e i l n o r s x )
  2.     (setq r (ssadd))
  3.     (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1) (410 . "Model"))))
  4.         (repeat (setq i (sslength s))
  5.             (setq e (ssname s (setq i (1- i)))
  6.                   o (vlax-ename->vla-object e)
  7.                   a (mapcar '(lambda ( x ) (cons (vla-get-tagstring x) (strcase (vla-get-textstring x)))) (vlax-invoke o 'getattributes))
  8.                   n (vla-get-effectivename o)
  9.                   x (assoc n l)
  10.             )
  11.             (if x
  12.                 (if (vl-some '(lambda ( x ) (vl-every 'equal a x)) (cdr x))
  13.                     (ssadd e r)
  14.                     (setq l (subst (vl-list* n a (cdr x)) x l))
  15.                 )
  16.                 (setq l (cons (list n a) l))
  17.             )
  18.         )
  19.     )
  20.     (sssetfirst nil r)
  21.     (princ)
  22. )

ELOQUINTET

  • Guest
Re: Delete duplicate blocks in a drawing
« Reply #7 on: October 28, 2015, 04:53:45 PM »
I am looking to erase blocks with duplicate attributes and it doesn't matter which one is kept. I tried your routine Lee Mac and it didn't appear to delete anything? Anyways hopefully this clarifies what I am looking for.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Delete duplicate blocks in a drawing
« Reply #8 on: October 28, 2015, 05:46:02 PM »
I am looking to erase blocks with duplicate attributes and it doesn't matter which one is kept. I tried your routine Lee Mac and it didn't appear to delete anything? Anyways hopefully this clarifies what I am looking for.

The current code merely selects the duplicates - this could easily be changed to a deletion.

ELOQUINTET

  • Guest
Re: Delete duplicate blocks in a drawing
« Reply #9 on: November 19, 2015, 03:17:28 PM »
Hey I apologize for my slow response. I tried to run this again and don't see anything being selected. I even did select previous and it said that there was nothing previously selected so maybe I'm not understanding you. Anyways, If it could be modified to just delete the duplicate blocks that would be great. Thanks