- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Found this a while back and it works perfectly.
I have modified it a wee bit to suit my accasional needs.
-HOWEVER-
The drawings I'm working on now, from another company, each have hundreds of these to remove, but the one-at-a-time manner of this program as written is not very efficient in this scenario. The attribute must be removed to facilitate follow-on processing.
Is there a way to easily modify this to check each block(insert) and, for each that has this attribute, remove the attribute from all of them in one go?
; found @
; forums.augi.com/showthread.php?94696-Deleting-an-attribute-from-a-block&highlight=attdel
; posted by inerb
; Modified by Greg B. to allow spaces for block name and attribute tag
;
; Modified again by SteveJ to allow block selection and automatic (hard-coded)
; attribute tag name for use on several objects with the same
; attribute to remove.
;
;;; Command to delete an attribute from a block
;
;;; Delete an attribute from a block
(defun c:ATTDEL (/ blkname attname bn bd en ed attlst)
;;; wedge -
(setq blkname (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))
;;; Ask user for block name
;;; (setq blkname (getstring "\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 "\nEnter the attribute Tag Name: "))
;;; PUT YOUR ATTRIBUTE TAG IN THE FOLLOWING LINE BETWEEN THE QUOTES
(setq attname "POLYGONDATA")
;; 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 block reference. Exiting ...")
) ;_ end of if
) ;_ end of progn
(princ "\nThat Block doesn't exist in this drawing. Exiting ...")
) ;_ end of if
(princ)
) ;_ end of defun
;(c:ATTDEL);; for testing
Thanks for any help and ideas,
Steve
Solved! Go to Solution.