Anuncios

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

Anonymous
1118 Vistas, 6 Respuestas

Change Attribute Tags by their Position instead of the Name

Hello, we got alot drawings that we convert from microstation to .DWG and now we have to replace every Attribute-Tag with our own Names - we got a Script, dont really know from where but its pretty straight forward.

 

;;; 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
  (vlax-for bo blocks
    ;; 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
  ) ;_ end of vlax-for
) ;_ end of defun

and we run it with the command

(RenAttrib "TESTBLK" "OLDTAG" "NEWTAG")

lets jump right at the problem-

The "OLDTAG" does change for the same blocks after every new convert from microstatio.

For example.

 

First DWG

Blockname: KI1

Tagname: KI1_1

Tagname2: KI1_2

 

Second DWG

Blockname: KI1

Tagname: KI1_3

Tagname2: KI1_4

-----------------------------------------

Even tho its the same block the Attribute Tags seem to count up and we cant use a Excel for the Tag names to maximise efficency with the .lsp

 

My Question:

Is it possible to set the reference of the Script to the position of the AttributeTag instead of the old name?

E.g.

(RenAttrib "BLOCKNAME" "FIRST NEW TAG" "SECOND NEW TAG")

Would be awesome if someone could tell me if its possible or how to do it. Or even "just" change the existing script.

 

P.S. if someone knows where the original script came from please post source below for credit.

 

Best regards!