Jump to content
bustr

Deleting Duplicate Attribute Tags

Recommended Posts

bustr

I have hundreds of drawings with attributes that are duplicated. I can't go through each individual drawing, call up BATTMAN and delete them one by one. I need a way to automate the process. The duplicates always show up in EATTE and show up most of the time in BATTMAN. I need a lisp that will find and delete duplicates shown in RED while leaving the originals intact.

 

Can anyone help?

 

 

EATTE.jpg

Share this post


Link to post
Share on other sites
Lee Mac

Try this:

 

(defun c:DelDupAtts ( / att tag )
   (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (if
           (and
               (eq :vlax-false (vla-get-isxref block))
               (eq :vlax-false (vla-get-islayout block))
           )
           (vlax-for obj block
               (if (eq "AcDbAttributeDefinition" (vla-get-objectname obj))
                   (if (member (setq tag (strcase (vla-get-tagstring obj))) att)
                       (vl-catch-all-apply 'vla-delete (list obj))
                       (setq att (cons tag att))
                   )                       
               )
           )
       )
       (setq att nil)
   )
   (vl-cmdf "_.attsync" "_N" "*")
   (princ)
)
(vl-load-com) (princ)

Note: The above code is modifying the Block Definition of all blocks with duplicate Attribute Tags and hence will not check whether the Attribute Values are also duplicate.

Share this post


Link to post
Share on other sites
bustr

Thanks! It seems to have worked but the attributes still show up in the Enhanced Attribute Editor and their values are lost when synchronizing. Do you know how to handle this? If not then thanks anyway for the lisp?

Share this post


Link to post
Share on other sites
Tharwat

Lee , hope you don't mind to participate with the thread . :roll:

 

That seems very interesting idea for a lisp to have fun with it , can you upload a copy of that attributed block ?

 

Thanks

Share this post


Link to post
Share on other sites
Tharwat

Hope this one that you looking for ....

 

(defun c:Test (/ e i n sn ss strings)(vl-load-com)
 ;;; Tharwat 28. march. 2012 ;;;
 (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (setq n (entnext sn))
     (while (not (eq (cdr (assoc 0 (setq e (entget n)))) "SEQEND" )
                 )
        (if (not (member (strcase (cdr (assoc 1 e))) strings))
          (setq strings (cons (strcase (cdr (assoc 1 e))) strings ))
          (vla-delete (vlax-ename->vla-object n))
          )
        (setq n (entnext n))
     )
     (setq strings nil)
   )
   (princ)
 )
 (princ)
)

Share this post


Link to post
Share on other sites
Lee Mac
Thanks! It seems to have worked but the attributes still show up in the Enhanced Attribute Editor and their values are lost when synchronizing. Do you know how to handle this? If not then thanks anyway for the lisp?

 

Everything seemed to work correctly in my brief tests before posting - the attributes should be removed from all references of the block after the AttSync.

Share this post


Link to post
Share on other sites
bustr

Some of the attribute tag names are the same but the ones listed below are not. Basically I just need a way to transfer the information from the attributes' values from the old to the new. If it were only a few drawings I would use battman to eliminate the duplicates and change their names one at a time, apply and synchronize. This works but I have hundreds of drawings and doing them one at a time isn't practical

 

old_border (COUNT) new_border (COUNT)

 

04-16-90 (2) START_DATE (1)

04-17-90 (2) CHKD_DATE (1)

04-18-90 (2) APPD_DATE (1)

F.T.D. (2) DRAWN_BY (1)

C.B. (2) CHECKED_BY (1)

APP (2) APPD_BY (1)

DES-0 (1) DESC-0 (1)

DES-1 (1) DESC-1 (1)

DES-2 (1) DESC-2 (1)

DES-3 (1) DESC-3 (1)

DES-4 (1) DESC-4 (1)

 

 

 

The following tags are the same in both borders but are duplicated in the old. Thus when I rename the old to the new and redefine it I have multiple instances in EATTEDIT and on the drawing. Whe I synchronize them their values are lost.

 

DWGNO (3)

TITLE1 (2)

TITLE2 (2)

borders.dwg

Share this post


Link to post
Share on other sites
pBe

I ran into the same problem before Lee, on a code that changes the width of the attributes. But there are cases the attributes were move from their default position changing the block definition reverts it to its original location.so I ended up using a selection set instead. Not sure if its the same case here though :unsure:

 

[b][color=blue]CODE REMOVED, Refer to post # 26[/color][/b] 

Edited by pBe
Remove Code

Share this post


Link to post
Share on other sites
bustr

Thanks Tharwat! I found that if I run the RenAttrib.lsp and rename and redefine the border then the synchronization works. The RenAttrib.lsp requires typing or script to make it work. The text is below. Ive attached the lisp if anyone wants a copy to use for themselves.

 

 

Thanks again.

 

 

ATTDIA 0

ATTREQ 0

-INSERT

old_border=C:\mike\autocad\RenAttrib\old_border.dwg

25,0

1

(RenAttrib "old_border" "04-16-90" "START_DATE")

(RenAttrib "old_border" "04-17-90" "CHKD_DATE")

(RenAttrib "old_border" "04-18-90" "APPD_DATE")

(RenAttrib "old_border" "F.T.D." "DRAWN_BY")

(RenAttrib "old_border" "C.B." "CHECKED_BY")

(RenAttrib "old_border" "APP" "APPD_BY")

(RenAttrib "old_border" "DES-0" "DESC-0")

(RenAttrib "old_border" "DES-1" "DESC-1")

(RenAttrib "old_border" "DES-2" "DESC-2")

(RenAttrib "old_border" "DES-3" "DESC-3")

(RenAttrib "old_border" "DES-4" "DESC-4")

-PURGE

A

*

N

-PURGE

A

*

N

-PURGE

A

*

N

-PURGE

A

*

N

-RENAME

B

old_border

new_border

-INSERT

new_border=C:\mike\autocad\RenAttrib\new_border.DWG

25,0

1

attsync n new_border

ATTDIA 1

ATTREQ 1

renattrib.lsp

Edited by bustr

Share this post


Link to post
Share on other sites
bustr

Tharwat's lisp worked but it erased the value of the attribute tag "BY-0" and "DATE-0". Could this have to do with the justification or width factor?

 

Also lost the "04-18-90" value.

Edited by bustr
update

Share this post


Link to post
Share on other sites
bustr

Lee and pBe

 

Thanks for the effort. I'm still losing all of the values. This border may be beyond all repair.

Share this post


Link to post
Share on other sites
pBe
Lee and pBe

 

Thanks for the effort. I'm still losing all of the values. This border may be beyond all repair.

 

I tested Lee's code here, its works as well, I only suggested processing all the blocks indivudually thinking that would produce the result you want. but apparently not.

 

But dont fret, there still hope yet . Its just that I, tharwat nor Lee doesnt really understand what you are trying to achieve is all. but we'll get there.

 

Cheers

Share this post


Link to post
Share on other sites
bustr

I'm basically trying to migrate the information for the old border to the new. But the oddly named tags and the duplicates in the old make it difficult. My solution was to find a way to delete the dups and rename the tags without having to type or copy and paste then just rename and redefine the border. I'm sure there are better ways but I don't have that kind of knowledge.

 

Thanks

Share this post


Link to post
Share on other sites
pBe

On your posted sample border. what are we looking at? There are tow borders "OLD" and "NEW". The title of this thread is Deleting Attribute Tags:

Where and what are the duplicates were looking for here?

 

Ooops you posted a reply before i even finish typing.

Anyhoo... so migrate the data then delete the "old" border.

 

Now I need you to be specific what to keep and what to delete.

 

Ooops again. I guess you already posted the answer long before I asks. :)

I think this can be done in one go. patience bustr.

Share this post


Link to post
Share on other sites
Tharwat
Tharwat's lisp worked but it erased the value of the attribute tag "BY-0" and "DATE-0". Could this have to do with the justification or width factor?

 

Also lost the "04-18-90" value.

 

I did not get you , can you explain more ?

Share this post


Link to post
Share on other sites
bustr

pBe

 

The duplicates are in the old_border. Their tags are listed below. The numbers is parentheses are the number of times they occur in the block.

 

TAG COUNT

 

04-16-90 (2)

04-17-90 (2)

04-18-90 (2)

F.T.D. (2)

C.B. (2)

APP (2)

DWGNO (3)

TITLE1 (2)

TITLE2 (2)

Share this post


Link to post
Share on other sites
bustr

Tharwat

 

Sorry about that. I've attached a drawing with a border that has been populated with information. The leaders at the bottom point to the information that goes missing when I run the lisp.

Drawing2.dwg

Share this post


Link to post
Share on other sites
pBe
pBe

 

The duplicates are in the old_border. Their tags are listed below. The numbers is parentheses are the number of times they occur in the block.

 

 

Lets make this clear, it became double AFTER you run the script and not before? I.m looking at the sample drawing i did not see duplicates on the old border?

Are you telling me now you need to REPAIR the borders already process by the script? or run a new lisp to avoid the duplicates from happening?

Share this post


Link to post
Share on other sites
bustr
Lets make this clear, it became double AFTER you run the script and not before? I.m looking at the sample drawing i did not see duplicates on the old border?

Are you telling me now you need to REPAIR the borders already process by the script? or run a new lisp to avoid the duplicates from happening?

 

 

Sorry about that. I must be getting flustered. I'm re-uploading the drawing. This one will have the duplicates.

borders.dwg

Share this post


Link to post
Share on other sites
Tharwat
Sorry about that. I must be getting flustered. I'm re-uploading the drawing. This one will have the duplicates.

 

I can't see the duplicates words except the one (date) . Is this right ?

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...