TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ELOQUINTET on October 20, 2015, 05:08:10 PM

Title: Delete duplicate blocks in a drawing
Post by: ELOQUINTET 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
Title: Re: Delete duplicate blocks in a drawing
Post by: David Bethel on October 22, 2015, 07:32:21 AM
Sorry, I don't know much about dynamic blocks.  -David
Title: Re: Delete duplicate blocks in a drawing
Post by: Lee Mac 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?
Title: Re: Delete duplicate blocks in a drawing
Post by: ELOQUINTET 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
Title: Re: Delete duplicate blocks in a drawing
Post by: Lee Mac 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?
Title: Re: Delete duplicate blocks in a drawing
Post by: roy_043 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.
Title: Re: Delete duplicate blocks in a drawing
Post by: Lee Mac 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. )
Title: Re: Delete duplicate blocks in a drawing
Post by: ELOQUINTET 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.
Title: Re: Delete duplicate blocks in a drawing
Post by: Lee Mac 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.
Title: Re: Delete duplicate blocks in a drawing
Post by: ELOQUINTET 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