; ABTagRepN replaces all matching Block Attribute Tag Name with New Name ; OP: ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-the-same-tag-value-extension-for-batch-attribute/m-p/13396314#M480632 (defun c:ABTagRepN (/ atagrep atgcur atgnew doc fnb fnd ss tmp) (vl-load-com) ; atagrep replaces matching attribute tag name with new & returns number replaced ; Note: attribute tag names are uppercase & cannot have spaces ; Arguments: ; vlobj = vl object ; tagcur = current tag name ; tagnew = new tag name ; Usage Example: ; The following will replace all Attribute Definitions with Tag name: CurrentTagName with: NewTagName ; (atagrep obj "CurrentTagName" "NewTagName") ; OP: ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-the-same-tag-value-extension-for-batch-attribute/m-p/13399789#M480739 (defun atagrep (vlobj tagcur tagnew / c n ss) (setq c 0) (foreach attref (vlax-invoke vlobj 'getattributes) (if (eq (strcase tagcur) (strcase (vla-get-tagstring attref))) (progn (vla-put-TagString attref tagnew) (setq c (1+ c)) ; increment # found ) ) ) ; return # items replaced c ) ; defun (setq fnd 0 fnb 0 doc (vla-get-activedocument (vlax-get-acad-object)) ) (while (not atgcur) (setq atgcur (getstring "\nEnter Current Attribute Tag Name to Replace: ")) (if(zerop(strlen atgcur))(setq atgcur nil)) ) (while (not atgnew) (setq atgnew (getstring "\nEnter New Attribute Tag Name: ")) (if(zerop(strlen atgnew))(setq atgnew nil)) ) (vla-startundomark doc) ; replace all inserted blocks with attributes & attribute definitions (vlax-for blk (vla-get-blocks doc) (if (eq :vlax-false (vla-get-isxref blk)) (cond ((eq :vlax-true (vla-get-IsLayout blk)) ; search all inserted blocks with attributes (vlax-for obj blk (if (and (eq "AcDbBlockReference" (vla-get-ObjectName obj)) (eq :vlax-true (vla-get-HasAttributes obj)) (vlax-write-enabled-p obj) ) (if (not (zerop (setq tmp (atagrep obj atgcur atgnew)))) ; replace tag (setq fnb (+ fnb tmp)) ; increment # found ) ; if ) ; if ) ; vlax-for obj ) (T (vlax-for obj blk ; search all attribute definitions (if (and (eq (vla-get-objectname obj) "AcDbAttributeDefinition") (eq (strcase atgcur) (strcase (vla-get-TagString obj))) (vlax-write-enabled-p obj) ) (progn (vla-put-TagString obj atgnew) ; replace tag (setq fnd (1+ fnd)) ; increment # found ) ; progn ) ; if ) ; vlax-for obj ) ; T ) ; cond ) ; if ) ; vlax-for (vla-endundomark doc) (princ (strcat "\nFound & Replaced [" (itoa fnb) "] Inserted Block Attribute Tags.")) (princ (strcat "\nFound & Replaced [" (itoa fnd) "] Block Definition Attribute Tags.")) (princ) ; clean exit ) (princ "\n Enter command [ABTagRepN] to start.")(princ)