Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete Attributes

16 REPLIES 16
Reply
Message 1 of 17
jjorovi
3687 Views, 16 Replies

Delete Attributes

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?

16 REPLIES 16
Message 2 of 17
devitg
in reply to: jjorovi

Do you mean to remove the attributte definitions or the  values at the attributes.

Please upload a dwg sample or send it offline

Message 3 of 17
pbejse
in reply to: jjorovi


@jjorovi wrote:

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?


Is that attribute values or ATTDEFS?

 

Message 4 of 17
pbejse
in reply to: devitg


@devitg wrote:

Do you mean to remove the attributte definitions or the  values at the attributes.

Please upload a dwg sample or send it offline


 

Did you get a reply on this from the OP devtg?

Message 5 of 17
devitg
in reply to: pbejse

no

Message 6 of 17
stevor
in reply to: jjorovi

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.

S
Message 7 of 17
jjorovi
in reply to: devitg

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

 

Message 8 of 17
marko_ribar
in reply to: jjorovi

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.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 9 of 17
devitg
in reply to: marko_ribar

Hi Marko ribar , as I see it delete both the att value , and the ATTDEF . Seem to be it is what the OP need.
Message 10 of 17
jjorovi
in reply to: marko_ribar

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

Message 11 of 17
pbejse
in reply to: jjorovi

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

 

Message 12 of 17
pbejse
in reply to: pbejse

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

 

Message 13 of 17
devitg
in reply to: pbejse

Thanks pBe , for it , very clear.

 

Message 14 of 17
pbejse
in reply to: devitg


@devitg wrote:

Thanks pBe , for it , very clear.

 


You are welcome devitg 🙂 

 

Glad it works for you.

 

Cheers

Message 15 of 17
kcarver
in reply to: pbejse

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?

Message 16 of 17
kcarver
in reply to: kcarver

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.

Message 17 of 17
rtaassociates
in reply to: jjorovi

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.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost