TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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
(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
-
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.
-
ah, thats me stuffed then.
Thanks
-
ah ha, using the gatte command has let me select the block and attribute to delete.
-
Something like this?
(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)
)
-
Perhaps, command _.attsync helps?
-
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
-
Hmmm.. I wasn't expecting that :oops:
Perhaps altering the block definition is the only way :|
-
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 ).
-
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 :-(
-
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.
-
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 :-)
-
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
-
A slight reworking and a wrapper for you:
(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)
)
-
brilliant
I'll have a look at this soon.
Thanks
-
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.
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
-
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:
(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)
)
-
ahh I see, perfect.
Cheers Lee!