Jump to content
Foxxy1

Replace/Redefine Block Removing Attributes

Recommended Posts

anujkumar

i'm not a autocad expert but just a architecture student and not sure how much name of blocks or other data is relevant but i had same problem, i guess. i copied the block in a different file and exploded it. removed the attribute text and made a new blcok with a new name. i then copied this block and went to original file and opened the block with att in block editor i removed everything from the block and pasted the copied block from diff fiel. came out of block editor after saving the block and exploded everthing in the file. tada now i have the blocks without attributes. i guess this might work!!!

Share this post


Link to post
Share on other sites
ibach

OK, I found the final solution for this, it needs some polishing in a lisp part, if someone feels up to it, please do it...

PART ONE:

make attribute invisible in all visibility states of a block (that is why it still shoves in properties even when actually deleted in block reference)

PART TWO:

use this lisp to delete the attribute:

; found @ [url]http://forums.augi.com/showthread.php?t=94696&highlight=attdel[/url]
; posted by inerb
;
; Modified by Greg B. to allow spaces for block name and attribute tag
;
;;; Command to delete an attribute from a block
;
(vl-load-com)
(defun c:ATTDEL (/ blkname attname bn bd en ed attlst)
;; Ask user for block name
(setq blkname (getstring T "\nEnter the block's name: "))
;; Check if block exists
(if (setq bn (tblobjname "BLOCK" blkname))
(progn
;; Get list of attributes
(setq bd     (entget bn) ;Block def's data
en     (cdr (assoc -2 bd)) ;1st entity insie block
attlst nil ;Initialize list to empty
) ;_ end of setq
(while en ;Step through all entities in block
(setq ed (entget en)) ;Get entity's data
;; Check if entity is an attribute definition
(if (= "ATTDEF" (cdr (assoc 0 ed)))
;; Add to list of attributes
(setq attlst (cons (cons (strcase (cdr (assoc 2 ed))) (vlax-ename->vla-object en)) attlst))
) ;_ end of if
(setq en (entnext en)) ;Get next entity
) ;_ end of while
 
;; Ask user for attribute tag name
(setq attname (getstring T "\nEnter the attribute Tag Name: "))
;; Check if attribute exists
(if (setq en (assoc (strcase attname) attlst))
(progn
(setq ed (cdr en)) ;Get the VLA object of the attribute
(vla-Delete ed)
(princ
"\nAttribute successfully deleted from block definition.\nSynchronizing block references ..."
) ;_ end of princ
(command "_.ATTSYNC" "_Name" blkname)
) ;_ end of progn
(princ "\nThat Attribute doesn't exist in this drawing. Exiting ...")
) ;_ end of if
) ;_ end of progn
(princ "\nThat Block doesn't exist in this drawing. Exiting ...")
) ;_ end of if
(princ)
) ;_ end of defun

please someone, intefrate those two parts in one LSP

Edited by ibach

Share this post


Link to post
Share on other sites
RobDraw

Why do that, if ATTSYNC does what is needed?

Share this post


Link to post
Share on other sites
ttray33y

ATTSYNC perhaps?

Share this post


Link to post
Share on other sites
RobDraw

Cue Twilight Zone theme.

Share this post


Link to post
Share on other sites
ibach
Why do that, if ATTSYNC does what is needed?

 

Because it does not. This problem is as old as dynamic blocks.

Here's the scenario:

 

Create dynamic block attribute definition.

insert some value in attribute.

open block in block editor and delete attribute.

Do PURGE.

Now try ATTSYNC- no way! the drawing contains no attributed blocks.

BATTMAN cannot select the block either.

 

to solve this it is enough to recreate attribute in the bloc, than delete it and do attsync before using purge.

 

There's also another bug considering visibility parameter, fields and attribute definition that I was able to recreate.

In such case recreating than deleting and ATTSYNC is not enough. It simply will not go away from properties. In such case it must first be made invisible in all visibility states of a block, than deleted in the same manner.

 

That is why recreating the attribute, making it invisible in all visibility states, saving the block,than deleting the attribute using the above LSP (delete the attribute and ATTSYNC) solves the problem.

 

If one wants to have unique solution one has to make the lisp that :

 

1) checks if the attribute exists in the block

2) check if visibility states exist in a block

 

if 1 and 2 is true

make attribute invisible in all the states, than delete it and attsync (as the lsp above does)

 

if 1=true 2=false

just use the lisp above

 

if 1=false and 2=false

recreate attribute, use the lisp above

 

if 1 and 2 = false

recreate attribute, make attribute invisible in all the states, than delete it and attsync

Edited by ibach

Share this post


Link to post
Share on other sites
RobDraw

I do it all the time, except that I don't purge. Maybe, that is why it doesn't work for you.

Share this post


Link to post
Share on other sites
ibach

It's not necessarily me that does deleting or purging I just get blocks with visible attribute and no attribute definitions, inherited from other people. What I need is to get rid of such FAST.

I have just described the symptoms and procedures to solve the problem universally (for ALL the variants of the problem).

 

And, yes, the purge makes the problem in above scenario. It is easy if you are the only one who works on a project, but usually one is not the only one... people do all sort of a **** to my dwg that I must be able to repair. (I like data export a lot...)

 

What I have asked for is if someone have enough time to look into writing the LSP to fix this sort of problem FAST.

I simply do not have time to edit blocks manually for this to be done, and I do get a lot of such blocks lately.

 

That it can be done manually is clear (at least to one who had read my post).

 

In this way you would have the LSP that can delete attribute and attributes residues from blocks and dynamic blocks seamlessly.

 

What I really do not need is arguing if that LSP is neded.

IT IS!

For me to speed up my job and for those that do not have time to argue with Autodesk that there is a bug in Autocad that does not allow ATTSYNC on blocks without the attributes even though the attribute value is clearly stated in properties of a block that does not contain the actual attribute definition at all!

Share this post


Link to post
Share on other sites
RobDraw

New questions should be posted in new threads. There was no mention of dynamic blocks in this one and I don't think it has anything to do with the problem. It was a procedural issue. Try over at the LISP forum. You will get more input for your question there, than in this thread.

Share this post


Link to post
Share on other sites
ibach

Have you even read the thread?!

 

To remind you:

"Replace/Redefine Block Removing Attributes

 

First off I want to say thanks for allowing me to join in this exchange of knowledge on this forum.

 

I'm working with some "dirty" blocks that contain several attributes. I've cleaned the blocks up by wblocking, cleaning, & purging the newly created block. I also removed any attributes within the file, including those within blocks within the file. I then renamed the file and inserted it into the drawing, and did a replace block with another through express tools. The problem that I have is the blocks are replaced with the clean version, yet the attributes remain. Is there a solution to this. I do not want any attributes to remain and the only way I know how to fix it is to replace them one at a time. Thank you for your help.

 

Also, I'm using AutoCAD 2004."

 

Is finally solved by my solution, it only needs automation...

Just stating that there is ATTSYNC command in autocad will help almost no one.

 

Now leave some room for someone to write the answer, please.

Even I might do that if I find enough time.

Share this post


Link to post
Share on other sites
RobDraw

Please, go ahead and keep this eight year old thread alive.

Share this post


Link to post
Share on other sites
Lee Mac

To clarify, are you simply looking to remove all attributes from all references of a given block?

Share this post


Link to post
Share on other sites
Lee Mac

FWIW, the following will process all attributed blocks (including all nested attributed blocks) and will remove any attributes which are not present in the corresponding block definition for each block:

([color=BLUE]defun[/color] c:fixbadattblocks ( [color=BLUE]/[/color] bkc bln doc lst tmp )
   ([color=BLUE]setq[/color] doc ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))
         bkc ([color=BLUE]vla-get-blocks[/color] doc)
   )
   ([color=BLUE]vlax-for[/color] blk bkc
       ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=BLUE]:vlax-false[/color] ([color=BLUE]vla-get-isxref[/color] blk))
           ([color=BLUE]vlax-for[/color] obj blk
               ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] [color=MAROON]"AcDbBlockReference"[/color] ([color=BLUE]vla-get-objectname[/color] obj))
                        ([color=BLUE]=[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-hasattributes[/color] obj))
                        ([color=BLUE]or[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]assoc[/color] ([color=BLUE]setq[/color] bln ([color=BLUE]vla-get-name[/color] obj)) lst))
                            ([color=BLUE]and[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]cons[/color] bln (gettags ([color=BLUE]vla-item[/color] bkc bln))))
                                 ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] tmp lst))
                            )
                        )
                   )
                   ([color=BLUE]foreach[/color] att ([color=BLUE]vlax-invoke[/color] obj 'getattributes)
                       ([color=BLUE]or[/color] ([color=BLUE]member[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-tagstring[/color] att)) ([color=BLUE]cdr[/color] tmp))
                           ([color=BLUE]and[/color] ([color=BLUE]vlax-write-enabled-p[/color] att)
                                ([color=BLUE]vla-delete[/color] att)
                           )
                       )
                   )
               )
           )
       )
   )
   ([color=BLUE]vla-regen[/color] doc [color=BLUE]acallviewports[/color])
   ([color=BLUE]princ[/color])
)
([color=BLUE]defun[/color] gettags ( def [color=BLUE]/[/color] rtn )
   ([color=BLUE]vlax-for[/color] obj def
       ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"AcDbAttributeDefinition"[/color] ([color=BLUE]vla-get-objectname[/color] obj))
           ([color=BLUE]setq[/color] rtn ([color=BLUE]cons[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-tagstring[/color] obj)) rtn))
       )
   )
   rtn
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Share this post


Link to post
Share on other sites
ibach

You are the master! That' s nice.

 

That is what it means to "READ THE THREAD" the right way.

 

Bravo.

 

(I'll test it, but I do believe that it works.)

 

Sure as hell, It works at all the examples....

 

Now, as this is lsp that works on ALL the blocks, it might be practical to do the same on a particular block, so the user would have a bit more control of what is going on.

 

Anyway, Lee is the one that really does use his mind to help, and he succeeds again.

 

PS:

I cannot stop admiring the simplicity of your code. It is always elegant.

Edited by ibach

Share this post


Link to post
Share on other sites
ttray33y
Because it does not. This problem is as old as dynamic blocks.

Here's the scenario:

 

Create dynamic block attribute definition.

insert some value in attribute.

open block in block editor and delete attribute.

Do PURGE.

Now try ATTSYNC- no way! the drawing contains no attributed blocks.

BATTMAN cannot select the block either.

 

to solve this it is enough to recreate attribute in the bloc, than delete it and do attsync before using purge.

 

There's also another bug considering visibility parameter, fields and attribute definition that I was able to recreate.

In such case recreating than deleting and ATTSYNC is not enough. It simply will not go away from properties. In such case it must first be made invisible in all visibility states of a block, than deleted in the same manner.

 

That is why recreating the attribute, making it invisible in all visibility states, saving the block,than deleting the attribute using the above LSP (delete the attribute and ATTSYNC) solves the problem.

 

If one wants to have unique solution one has to make the lisp that :

 

1) checks if the attribute exists in the block

2) check if visibility states exist in a block

 

if 1 and 2 is true

make attribute invisible in all the states, than delete it and attsync (as the lsp above does)

 

if 1=true 2=false

just use the lisp above

 

if 1=false and 2=false

recreate attribute, use the lisp above

 

if 1 and 2 = false

recreate attribute, make attribute invisible in all the states, than delete it and attsync

damn, thanks for this info though i never encounter this problem my whole life using cad.

this is noted already.

again many thanks.

 

and to Master Lee, tnx for this routine it will help me in the future.

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