Change every Attribute Tag Gloabally

Change every Attribute Tag Gloabally

Anonymous
Not applicable
996 Views
2 Replies
Message 1 of 3

Change every Attribute Tag Gloabally

Anonymous
Not applicable

Hello everyone ,

is there a way to change all Attribute Names(Tags) into  " x "  globally ?

Maybe already a .lsp ? i searched everywhere and couldnt find a way to change all tags without renaming them manually.

 

If someone is so kind to fix it into the "Change attribute Tag" Script would be super awesome!

 

First for mor clearification:

autocad-tips-attributes-battman-1.png

A script or makro should change the Tag "NO" to "X1" and "DATE" to "X2" without me typing the old tag somehere (50.000 Attribute tags to type 😕 )

 

Script that i am useing right now (Only for 2 or 3 blocks tho)

(defun C:RAT (/ RenAttrib ; local function
	        data^)

 ;;; Rename attributes
 (defun RenAttrib ($blk $old $new / blocks bo eo ao)
  ;; Get blocks collection in current drawing
  (setq blocks (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
  ;; Step through all blocks
  (if (setq bo (vla-item blocks $blk))
   ;; Step through all entities inside block
   (vlax-for eo bo
    (cond
     ;; If attdef & in target block & old tag
     ((and (= (vla-get-ObjectName eo) "AcDbAttributeDefinition")
           (= (strcase (vla-get-Name bo)) (strcase $blk))
           (= (vla-get-TagString eo) $old)
      ) ;_ end of and
      (vla-put-TagString eo $new) ;Change to new name
     )
        
     ;; If block reference & target block
     ((and (= (vla-get-ObjectName eo) "AcDbBlockReference")
           (= (strcase (vla-get-EffectiveName eo)) (strcase $blk))
      ) ;_ end of and
      ;; Step through all attributes
      (foreach ao (vlax-safearray->list (vlax-variant-value (vla-GetAttributes eo)))
       ;; Check if target attrib
       (if (= (strcase (vla-get-TagString ao)) (strcase $old))
        (vla-put-TagString ao $new) ;Change to new name
       ) ;_ end of if
      ) ;_ end of foreach
     )
    ) ;_ end of cond
   ) ;_ end of vlax-for
  ); if  
 );_ end of defun

  
 ; here start C:RAT  
 (setq data^ '( ("Block1" ("oldTag1" "newTag1")
	                  ("oldTag2" "newTag2")
	                  ("oldTag3" "newTag3")
	        ); list
                ("Block2" ("oldTag1" "newTag1")
	                  ("oldTag2" "newTag2")
	                  ("oldTag3" "newTag3")
	        ); list
              ); list
       
 ); setq

 (foreach blk data^
  (foreach item blk
   (RenAttrib blk (car item) (cadr item))
  ); foreach
 ); foreach

 (princ) 
); C:RAT

 

Best regards thanks for the work guys!

 

Inb4 some asks - cant post a example .dwg

0 Likes
Accepted solutions (1)
997 Views
2 Replies
Replies (2)
Message 2 of 3

ronjonp
Mentor
Mentor

One bad side effect of renaming tags is once you attsync, the values will revert to default .. you sure you want this?

0 Likes
Message 3 of 3

ronjonp
Mentor
Mentor
Accepted solution

Here is a quick example:

(defun c:foo (/ i f)
  ;; RJP » 2019-05-22
  ;; Renames all attribute tags in blocks to X1,X2 etc... USE AT YOUR OWN RISK!!
  (vlax-for a (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (cond ((= 0 (vlax-get a 'islayout) (vlax-get a 'isxref))
	   (setq i 0)
	   (vlax-for b a
	     (and (= "AcDbAttributeDefinition" (vla-get-objectname b))
		  (vlax-write-enabled-p b)
		  (vla-put-tagstring b (setq f (strcat "X" (itoa (setq i (1+ i))))))
	     )
	   )
	  )
    )
  )
  (and f (command "_attsync" "_n" "*"))
  (princ)
)
(vl-load-com)
0 Likes