Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Moshe-A
en respuesta a: Anonymous

@Anonymous  hi,

 

1. the lisp function you post looks good although i can not test it (cause you did not post a dwg) but it has a 'little' drawback...for each block it scan the whole database time and time again so i correct it to be effective (hope you do not (or the author) mind Emoticono riéndose a carcajadas)

2. in order to base the program on attribute coordinates you have to provide those coordinates to the function and i assume you do not have that beyond that you could not be sure that attributes are not moved from one convert to another. so this still must be base on tag names. 

3. attached my version to solved this called RAT (rename attributes) and it starts by defining a list of blocks and attributes name all strings. you need to populate this list with your blocks name and the attributes old tag and the new tag to be replaced. make sure not to spoil the format, each sub list starts with the block name and continue with repeating old tag and new tag. each name (string) start and ends with double quotes so make sure not to miss that.

by the way do you know in advance what will be the old tags or you have to open each converted drawing and find them?

 

enjoy

Moshe

 

 

(setq data^ '( ("Block1" ("oldTag1" "newTag1")
	                 ("oldTag2" "newTag2")
	                 ("oldTag3" "newTag3")
	       ); list
               ("Block2" ("oldTag1" "newTag1")
	                 ("oldTag2" "newTag2")
	                 ("oldTag3" "newTag3")
	       ); list
             ); list
       
 ); setq

and here is the whole program.

 

(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