TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Pad on December 17, 2010, 11:06:59 AM

Title: delete invisible attributes help
Post by: Pad on December 17, 2010, 11:06:59 AM
Hello

I'm trying to delete invisible attributes in a drawing.  I don't want to burst the blocks.
A client uses some CAD software which displays the invisible attributes, so I want to remove them all together.
I found this lisp here http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Remove-Invisible-Attributes-from-Blocks/m-p/1517876

Code: [Select]
(defun delInvisAtts (bname / )
(if (tblsearch "BLOCK" bname)
(progn
(vl-load-com)
(setq blk (vla-item
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
bname
)
)
(vlax-for ent blk
(if (and (eq (vla-get-objectname ent) "AcDbAttributeDefinition")
(eq (vla-get-invisible ent) :vlax-true)
)
(vla-delete ent)
)
)
)
)
)

But I can't get it to work, wondered if somebody could show me where I'm going wrong?


Thanks P
Title: Re: delete invisible attributes help
Post by: T.Willey on December 17, 2010, 11:13:03 AM
That only deletes them from the definition, not the inserts.  You would have to get the inserts for said block, and then step through the attributes associated with the insert, and then delete those if they are invisible.
Title: Re: delete invisible attributes help
Post by: Pad on December 17, 2010, 11:19:32 AM
ah, thats me stuffed then.
Thanks
Title: Re: delete invisible attributes help
Post by: Pad on December 17, 2010, 11:28:03 AM
ah ha, using the gatte command has let me select the block and attribute to delete.
Title: Re: delete invisible attributes help
Post by: Lee Mac on December 17, 2010, 12:08:29 PM
Something like this?

Code: [Select]
(defun c:DIA nil (c:DeleteInvisibleAttributes))

(defun c:DeleteInvisibleAttributes ( / ss ) (vl-load-com)
  ;; Example by Lee Mac 2010 - www.lee-mac.com

  (if (ssget '((0 . "INSERT") (66 . 1)))
    (progn
      (vlax-for obj
        (setq ss
          (vla-get-ActiveSelectionSet
            (vla-get-ActiveDocument (vlax-get-acad-object))
          )
        )
        (mapcar
          (function
            (lambda ( attrib )
              (if (eq :vlax-true (vla-get-Invisible attrib))
                (vla-delete attrib)
              )
            )
          )
          (vlax-invoke obj 'GetAttributes)
        )
      )
      (vla-delete ss)
    )
  )
  (princ)
)
Title: Re: delete invisible attributes help
Post by: kpblc on December 17, 2010, 02:20:40 PM
Perhaps, command _.attsync helps?
Title: Re: delete invisible attributes help
Post by: Pad on December 17, 2010, 06:04:55 PM
Something like this?


thanks Lee.  It works very well but there is a small problem.
The tag and prompt order becomes messed up.

In this example the 'No' and 'code' attributes are invisible

before:
(http://www.theswamp.org/screens/dia1.jpg)
after:
(http://www.theswamp.org/screens/dia2.jpg)

cheers
P
Title: Re: delete invisible attributes help
Post by: Lee Mac on December 17, 2010, 06:27:03 PM
Hmmm.. I wasn't expecting that  :oops:

Perhaps altering the block definition is the only way  :|
Title: Re: delete invisible attributes help
Post by: T.Willey on December 17, 2010, 06:41:39 PM
Try erasing them from the definition, and the insert.  Run the code in the first post, and then Lee's ( either order, doesn't really matter ).
Title: Re: delete invisible attributes help
Post by: Lee Mac on December 17, 2010, 06:46:40 PM
Try erasing them from the definition, and the insert.  Run the code in the first post, and then Lee's ( either order, doesn't really matter ).

Or perhaps use AttSync I suppose after running the first code  :|

I would have thought one could alter the attributes for a single reference though  :-(
Title: Re: delete invisible attributes help
Post by: T.Willey on December 17, 2010, 07:18:20 PM
Try erasing them from the definition, and the insert.  Run the code in the first post, and then Lee's ( either order, doesn't really matter ).

Or perhaps use AttSync I suppose after running the first code  :|

I would have thought one could alter the attributes for a single reference though  :-(

I think the problem is with Acad's logic when it comes to attributes.  There is nothing referencing the definition ( of an attribute ) once you insert a block.  I have wondered how it happens before, and could only come up with the idea that is just goes in order, as it appears it does.  So if you erase the invisible attributes from the definition and the insert, then they should be in the same order.

Sidenote:  I wonder why they didn't just put a prompt dxf code with attributes references.  They are only stored in attribute definitions.
Title: Re: delete invisible attributes help
Post by: Lee Mac on December 17, 2010, 07:37:14 PM
Try erasing them from the definition, and the insert.  Run the code in the first post, and then Lee's ( either order, doesn't really matter ).

Or perhaps use AttSync I suppose after running the first code  :|

I would have thought one could alter the attributes for a single reference though  :-(

I think the problem is with Acad's logic when it comes to attributes.  There is nothing referencing the definition ( of an attribute ) once you insert a block.  I have wondered how it happens before, and could only come up with the idea that is just goes in order, as it appears it does.  So if you erase the invisible attributes from the definition and the insert, then they should be in the same order.

That seems to be the case judging by the way the prompt order depends on the Sortents table of the block.

Sidenote:  I wonder why they didn't just put a prompt dxf code with attributes references.  They are only stored in attribute definitions.

That would be nice :-)
Title: Re: delete invisible attributes help
Post by: Pad on December 18, 2010, 11:02:10 AM
thanks guys.
I'l give the first lisp and attsync a go.

to be honest I'm a little bit confused about how to run the first lisp as its a function.
What is the corect syntax for running it?

Cheers
p
Title: Re: delete invisible attributes help
Post by: Lee Mac on December 18, 2010, 11:14:43 AM
A slight reworking and a wrapper for you:

Code: [Select]
(defun delInvisAtts ( bname ) (vl-load-com)
  (if (tblsearch "BLOCK" bname)
    (vlax-for obj
      (vla-item
        (vla-get-blocks
          (vla-get-activedocument (vlax-get-acad-object))
        )
        bname
      )
      (if (and (eq (vla-get-objectname obj) "AcDbAttributeDefinition")
               (eq (vla-get-invisible obj) :vlax-true)
          )
        (vla-delete obj)
      )
    )
  )
)


(defun c:test ( / bn )

  (delInvisAtts (setq bn (getstring t "\nBlock Name: ")))

  (vl-cmdf "_.attsync" "_N" bn)
  (princ)
)
Title: Re: delete invisible attributes help
Post by: Pad on December 20, 2010, 06:47:01 AM
brilliant
I'll have a look at this soon. 
Thanks

Title: Re: delete invisible attributes help
Post by: Pad on December 23, 2010, 09:33:54 AM
I've played around with this some more today.
The problem with attsync is that any attributes which have been repositioned during drafting are reset back to their original position.
The same thing happens with battman.

'Gatte' seems to be the best option, replacing the invisible attribute with a null value.

Code: [Select]
Enter block name: pt2

Known tag names for block: TYPE HEIGHT SPREAD GIRTH CODE NO LEVEL
Select attribute or type attribute name: code

Block: pt2   Attribute tag: CODE
Enter new text:

Number of inserts in drawing = 31  Process all of them? [Yes/No] <Yes>:

Please wait...
31 attributes changed.

Maybe the best way is to get a list of all the blocks with invisible attributes.  (setq BlocksInCtab (ssget "_X" (list (cons 0 "INSERT") (cons 66 1) (cons 410 (getvar 'CTAB))))) ?
Find out which attribute tag in the blocks are invisible and then parse all this info into the 'gatte' command.

P
Title: Re: delete invisible attributes help
Post by: Lee Mac on December 23, 2010, 09:37:01 AM
Why use GATTE? With the code in this thread you already have the Attribute Objects, just feed them a null textstring.

As a modification of my original code:

Code: [Select]
(defun c:NIA nil (c:NullInvisibleAttributes))

(defun c:NullInvisibleAttributes ( / ss ) (vl-load-com)
  ;; Example by Lee Mac 2010 - www.lee-mac.com

  (if (ssget '((0 . "INSERT") (66 . 1)))
    (progn
      (vlax-for obj
        (setq ss
          (vla-get-ActiveSelectionSet
            (vla-get-ActiveDocument (vlax-get-acad-object))
          )
        )
        (mapcar
          (function
            (lambda ( attrib )
              (if (eq :vlax-true (vla-get-Invisible attrib))
                (vla-put-TextString attrib "")
              )
            )
          )
          (vlax-invoke obj 'GetAttributes)
        )
      )
      (vla-delete ss)
    )
  )
  (princ)
)
Title: Re: delete invisible attributes help
Post by: Pad on December 23, 2010, 09:56:12 AM
ahh I see, perfect.
Cheers Lee!