There is a quick way to remove all attributes, including in nested blocks.
Looking some lisp in the forum, I can't find one code for remove this elements completely.
Suggestions?
Do you mean to remove the attributte definitions or the values at the attributes.
Please upload a dwg sample or send it offline
1. You can find code to modify the attibutes of the inserts, to be blanks, hence nothing shows.
2. Or, you can find code to redefine the blocks, to not include the attributes.
Look the drawing attached.
I need clean the furniture without explode the blocks.
I have some codes:
(defun tl_fld (v1 v2) (cdr (assoc v1 v2))) (defun c:attdel (/ ss cnt blk blkdat blknam blktblnam blknewdat blktbldat newblkdat atk_dbug nextent nextentdat nextenttyp endblklst ) (command "undo" "group") (setq atk_dbug nil) ;; (setq atk_dbug T) (if (setq ss (ssget (list (cons 0 "insert") (cons 66 1)))) (progn (setq cnt -1) (repeat (sslength ss) (setq blk (ssname ss (setq cnt (1+ cnt))) blkdat (entget blk) blknam (tl_fld 2 blkdat) newblknam (strcat blknam "_na") blknewdat (subst (cons 2 newblknam) (assoc 2 blkdat) blkdat ) blknewdat (subst (cons 66 0) (assoc 66 blknewdat) blknewdat ) ) (if (not (tblsearch "block" newblknam)) (progn (setq blktblnam (tblobjname "block" blknam) blktbldat (entget blktblnam) newblkdat (subst (cons 2 newblknam) (assoc 2 blktbldat) blktbldat ) newblkdat (subst (cons 70 (- (tl_fld 70 blktbldat) 2)) (assoc 70 blktbldat) newblkdat ) ) (if (entmake newblkdat) (progn (if atk_dbug (princ "\nStarting new block definition . . . ") ) (setq nextent (entnext blktblnam) nextentdat (entget nextent) nextenttyp (tl_fld 0 nextentdat) ) (while (and nextenttyp (/= nextenttyp "ENDBLK")) (if (/= nextenttyp "ATTDEF") (if (not (entmake nextentdat)) (princ "\nCan't make subentity.") (if atk_dbug (princ (strcat "\nAdding " nextenttyp " as subentity " (itoa xcnt) ) ) ) ) (if atk_dbug (princ "\nSkipping attribute definition.") ) ) (setq nextentdat nil nextenttyp nil ) (if (setq nextent (entnext nextent)) (setq nextentdat (entget nextent) nextenttyp (tl_fld 0 nextentdat) ) ) ) (setq endblklst (list (cons 0 "endblk") (cons 100 "AcDbBlockEnd") ) ) (if (not (entmake endblklst)) (princ "\nCan't terminate block definition") ) ) (princ "\nCan't start new block definition.") ) ) ) (if (tblsearch "block" newblknam) (progn (entdel blk) (entmake blknewdat) ) ) ) (setq ss nil) ) ) (command "undo" "end") (tl_$tlp) ) ______________________________________________________________________ (defun C:attdel2 (/ ent att) (vl-load-com) (and (setq ent (car (nEntSel "\nSelect attribute to delete: "))) (setq att (vlax-ename->vla-object ent)) (eq (vla-get-objectName att) "AcDbAttribute") (vla-delete att)) (princ)) ______________________________________________________________________ (defun c:attdel3 () (vl-load-com) (setq ss1 (ssget "X" '((0 . "INSERT"))) idx -1) (repeat (sslength ss1) (setq obj (vlax-ename->vla-object (ssname ss1 (setq idx (1+ idx))))) (if (= (vlax-get-property obj 'HasAttributes) :vlax-true) (progn (setq var (vlax-invoke-method obj 'getattributes) atts (vlax-safearray->list (vlax-variant-value var)) cnt -1 ) (repeat (length atts) (setq attref (nth (setq cnt (1+ cnt)) atts)) (vlax-invoke-method attref 'Delete) ) ) ) ) (princ) )
Here, try this, based on your last function :
(defun nestdelatt (obj / objn) (if (setq objn (acet-dxf -2 (tblsearch "BLOCK" (insname (vlax-vla-object->ename obj))))) (setq objn (entget objn '("*"))) ) (setq objn (acet-dxf -1 objn)) (while objn (if (eq (cdr (assoc 0 (entget objn))) "INSERT") (progn (delattbl (vlax-ename->vla-object objn)) (nestdelatt (vlax-ename->vla-object objn)) ) ) (if (eq (cdr (assoc 0 (entget objn))) "ATTDEF") (delatt objn) ) (setq objn (entnext objn)) ) ) (defun insname (obj / name) (if (eq (cdr (assoc 0 (entget obj))) "INSERT" ) (setq name (vla-get-effectivename (vlax-ename->vla-object obj))) ) name ) (defun delatt (obj) (if (eq (cdr (assoc 0 (entget obj))) "ATTDEF") (vlax-invoke-method (vlax-ename->vla-object obj) 'Delete) ) ) (defun delattbl (obj / var atts cnt attref) (if (and (eq (cdr (assoc 0 (entget (vlax-vla-object->ename obj)))) "INSERT" ) (= (vlax-get-property obj 'HasAttributes) :vlax-true) ) (progn (setq var (vlax-invoke-method obj 'getattributes) atts (if (vl-catch-all-error-p (setq atts (vl-catch-all-apply 'vlax-safearray->list (list (vlax-variant-value var)) ) ) ) nil atts ) cnt -1 ) (repeat (length atts) (setq attref (nth (setq cnt (1+ cnt)) atts)) (vlax-invoke-method attref 'Delete) ) ) ) ) (defun c:attdel (/ idx obj ss1) (setq ss1 (ssget "X" '((0 . "INSERT"))) idx -1 ) (repeat (sslength ss1) (setq obj (vlax-ename->vla-object (ssname ss1 (setq idx (1+ idx))))) (delattbl obj) (nestdelatt obj) ) (vl-cmdf "_.regen") (princ) ) (vl-load-com) (princ)
M.R.
Works great, but happen something curious.
Some invisible attributes are not removed and the blocks give an error.
Double-clicking on a block to edit it, it gives a message:
"The selection block is not editable attributes."
However, the code works well.
Thanks for responding and the time to help me.
Another:
(Defun c:AttDelN ( / _Att:Nested lst Blkcoll bn) ;;; pBe 10Jan2013 ;;; (vl-load-com) (defun _Att:Nested ( bname BC ) (if (not (member bname lst)) (progn (setq lst (cons bname lst) obj (vla-item BC bname)) (vlax-for itm obj (if (eq "AcDbBlockReference" (vla-get-objectname itm)) (progn (if (eq (vla-get-HasAttributes itm) :vlax-true) (foreach att (vlax-invoke itm 'GetAttributes) (vla-delete att))) (_Att:Nested (vla-get-name itm) BC)) (cond ((eq "AcDbAttributeDefinition" (vla-get-objectname itm)) (vla-delete itm)) ))))) ) (setq lst nil Blkcoll (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)))) (vlax-for itm Blkcoll (cond ((and (eq :vlax-false (vla-get-islayout itm)) (eq :vlax-false (vla-get-IsXref itm)) (not (wcmatch (setq bn (vla-get-name itm)) "`*D*")) (_Att:Nested (Vla-get-name itm) Blkcoll) )))) (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport) )
HTH
BTW:If you notice the previous code is named AttdelN for nested attributes
if you need to delete ALL and not just Nested attributes,
(Defun c:AttDelAll ( / _Att:Nested aDoc lst Blkcoll bn) ;;; pBe 10Jan2013 ;;; (vl-load-com) (defun _Att:Nested ( bname BC ) (if (not (member bname lst)) (progn (setq lst (cons bname lst) obj (vla-item BC bname)) (vlax-for itm obj (if (eq "AcDbBlockReference" (vla-get-objectname itm)) (progn (if (eq (vla-get-HasAttributes itm) :vlax-true) (foreach att (vlax-invoke itm 'GetAttributes) (vla-delete att))) (_Att:Nested (vla-get-name itm) BC)) (cond ((eq "AcDbAttributeDefinition" (vla-get-objectname itm)) (vla-delete itm)) ))))) ) (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq lst nil Blkcoll (vla-get-blocks aDoc)) (vlax-for itm Blkcoll (cond ((and (eq :vlax-false (vla-get-islayout itm)) (eq :vlax-false (vla-get-IsXref itm)) (not (wcmatch (setq bn (vla-get-name itm)) "`*D*")) (_Att:Nested (Vla-get-name itm) Blkcoll) )))) (vlax-for layout (vla-get-layouts aDoc) (vlax-for i (vla-get-block layout) (if (and (eq (vla-get-objectname i) "AcDbBlockReference") (eq (Vla-get-hasAttributes i) :Vlax-true) ) (foreach itm (vlax-invoke i 'GetAttributes) (vla-delete itm)) ) ) ) (vla-regen aDoc acActiveViewport) )
command: Attdelall
HTH
I know this is a forever ago code and thread but thanks for this code - the attdelall has been a life saver for me!
However, after running the program - if I go to redefine the block in the same drawing - the new attributes brought in from the redefine won't show - even after an attsync. They are in the block editor but will not show up in the properties bar or on screen. Any ideas?
BTW, if I save the drawing, close and then reopen - the block redefine works and the attributes display.
I'm trying to blank all of the attributes out in a drawing and then redefine all of the blocks with new attributes. My issue is several of the blocks have "preset" fields that won't redefine to new values if I don't first blank out the attributes for those blocks.
I'm getting an error on the attsync after redefining the block of "Error collecting attribute data."
Command: -insert Enter block name or [?] <DG_HIGHLY CONSUMABLES_BEVERAGES_ENERGY DRINK>: DG_HIGHLY CONSUMABLES_BEVERAGES_WATER=C:/UPDATES/05-01-16 MODEL/DG_HIGHLY CONSUMABLES_BEVERAGES_WATER.dwg
Duplicate definition of block _ArchTick ignored.
Units: Inches Conversion: 0'-1"
Specify insertion point or [Basepoint/Scale/Rotate]:
Command: attsync
Enter an option [?/Name/Select] <Select>: N
Enter name of block to sync or [?]: DG_HIGHLY CONSUMABLES_BEVERAGES_WATER
Error collecting attribute data.
ATTSYNC complete.
This works great but what if someone only wanted to remove some of the attributes. Editing the block with BEDIT seems to work but then their still there when selecting the block for input.