Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Renaming Attribute Tags?

  1. #1
    Member
    Join Date
    2008-09
    Posts
    9
    0 Did you find this post helpful? Yes

    Default Renaming Attribute Tags?

    Does anyone know of a way, or have a routine, that will edit the tag name (not the value) of an attribute in an existing block? I'm aware of BATTMAN's capability here but I have a HUGE number of drawings that require some tag renaming and I'm hoping to create a script to run overnight.

    Thanks,

    Randy

  2. #2
    I could stop if I wanted to msretenovic's Avatar
    Join Date
    2002-02
    Location
    Galloway, Oh
    Posts
    304
    0 Did you find this post helpful? Yes

    Lightbulb Re: Renaming Attribute Tags?

    Quote Originally Posted by rkingery View Post
    Does anyone know of a way, or have a routine, that will edit the tag name (not the value) of an attribute in an existing block? I'm aware of BATTMAN's capability here but I have a HUGE number of drawings that require some tag renaming and I'm hoping to create a script to run overnight.

    Thanks,

    Randy
    Randy,

    Give this a try:
    Code:
    (defun MKSxAttTagSet
              (obj   ;;variable - object to use
               att   ;;variable - attribute to set
               str   ;;variable - new tag name
               /
               atts  ;;variable - list of attributes
               bool  ;;variable - returns t if set, returns nil if not
               index ;;variable - index/counter
    )
      (setq    atts  (vlax-safeArray->list (variant-value (vla-getAttributes obj)))
        index 0
      )
      (repeat (length atts)
        (if    (= (vla-get-tagString (nth index atts)) att)
          (progn
        (vla-put-tagString (nth index atts) str)
        (vla-update (nth index atts))
        (setq bool t)
          )
        )
        (setq index (1+ index))
      )
      bool
    )
    You would call it like this:
    Code:
    (MKSxAttTagSet objBlk TagOld TagNew)
    This routine will update ALL attribute tags with the old name (TagOld). If nothing it updated, nil is returned; otherwise t is returned.
    Michael K. Sretenović
    Most folks are about as happy as they make up their minds to be.
    -Abraham Lincoln (1809-1865)
    -16th president of The United States of America (1861 - 1865)

  3. #3
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,492
    0 Did you find this post helpful? Yes

    Default Re: Renaming Attribute Tags?

    Similar to msretenovic's code. Although you simply give it the block's name, the old tag name & the new tag name. Renames these for both the block's definition as well as any block references (even when nested inside other blocks).
    Code:
    ;;; 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
    Example usage, at the command line (or in script). Assume block's name is TESTBLK, old Attrib Tag name is OLDTAG & new tagname is NEWTAG:
    Code:
    (RenAttrib "TESTBLK" "OLDTAG" "NEWTAG")
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  4. #4
    Member
    Join Date
    2008-09
    Posts
    9
    0 Did you find this post helpful? Yes

    Default Re: Renaming Attribute Tags?

    Thanks guys! Worked beautifully!

  5. #5
    I could stop if I wanted to chillme1's Avatar
    Join Date
    2006-05
    Location
    TN
    Posts
    270
    0 Did you find this post helpful? Yes

    Question Re: Renaming Attribute Tags?

    Newbie here: How could the be modified to rename several attribute tags and replace each with a corresponding new tag?
    Clint Hill
    Sr. Mechanical Designer/ Corporate CAD Manager
    ------------------
    Chemical Plant Design / Machine Design
    AutoCAD Mechanical 2014 SP1
    Win 7 64 32GB RAM NVidia FX4800

    "Check out the free e-mail discussion group at: www.waun.org"

  6. #6
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,492
    0 Did you find this post helpful? Yes

    Default Re: Renaming Attribute Tags?

    Quote Originally Posted by Clinton.Hill View Post
    Newbie here: How could the be modified to rename several attribute tags and replace each with a corresponding new tag?
    Renaming the insert's attributes is quite simple. A normal entmod does this without hassles, or as per the previous code. The tricky bit is to figure out which old name needs to be changed to which new name - you either need a prepared list of OldName->NewName or you need to ask the user all the time . Then a simple AttSync would suffice to modify any properties to the new attribute's definition.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  7. #7
    I could stop if I wanted to chillme1's Avatar
    Join Date
    2006-05
    Location
    TN
    Posts
    270
    0 Did you find this post helpful? Yes

    Smile Re: Renaming Attribute Tags?

    Do you have an example or tips on constructing a list of old and new attribute tag names that will be used by LISP:

    File content formatting
    File extension, etc.
    Other special considerations...

    Are there any links to instruction on or samples on how to use a list using either AUTOLISP or VISUAL LISP that you could forward?
    Clint Hill
    Sr. Mechanical Designer/ Corporate CAD Manager
    ------------------
    Chemical Plant Design / Machine Design
    AutoCAD Mechanical 2014 SP1
    Win 7 64 32GB RAM NVidia FX4800

    "Check out the free e-mail discussion group at: www.waun.org"

  8. #8
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,492
    0 Did you find this post helpful? Yes

    Default Re: Renaming Attribute Tags?

    Quote Originally Posted by Clinton.Hill View Post
    Do you have an example or tips on constructing a list of old and new attribute tag names that will be used by LISP:

    File content formatting
    File extension, etc.
    Other special considerations...

    Are there any links to instruction on or samples on how to use a list using either AUTOLISP or VISUAL LISP that you could forward?
    All you need is a list which you'll need to create for yourself. Something like this:
    Code:
    (setq attrename-list
      '(("BlockName1" ("OldAttName1.1" "NewAttName1.1") ("OldAttName1.2" "NewAttName1.2"))
       ("BlockName2" ("OldAttName2.1" "NewAttName2.1") ("OldAttName2.2" "NewAttName2.2"))
      )
    )
    Then you can step through that list and call something like my routine in post #3 thus:
    Code:
    (foreach block attrename-list
      (foreach attrename-pair (cdr block)
        (RenAttrib (car block) (car attrename-pair) (cadr attrename-pair))
      )
      (command "._ATTSYNC" "_Name" (car block))
    )
    Note though: this is untested, so you might have to tweak it a bit . And I think it's working only with case sensitivity - to get around that the RenAttrib defun needs some changes. Also this isn't the most efficient route as it's looping through the list and for each attribute rename pair goes through all the entities inside the DWG (there's probably a much faster method).
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  9. #9
    0 Did you find this post helpful? Yes

    Default Re: Renaming Attribute Tags?

    I found this on the web after receiving no help at the autodesk forum. I just tried loading the "RenAttrib" lisp. It loaded okay but when I put the text in the command line I get the error shown below.

    ILMST is the block name
    04-16-90 is the existing attribute tag name
    START_DATE is the new tag name I want to give it

    Command: (RenAttrib "ILMST" "04-16-90" "START_DATE")
    ; error: no function definition: VLAX-GET-ACAD-OBJECT


    I'm not a programmer so I don't know how to correct this. Can anyone help?

    Thanks

    Mike


    PS: If this can be done with a script that would be much easier.
    Last edited by bustr0giantcatfish974410; 2012-03-27 at 08:46 PM. Reason: Post Script

  10. #10
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,492
    0 Did you find this post helpful? Yes

    Default Re: Renaming Attribute Tags?

    It's using the Visual Lisp extensions - which aren't loaded by default. Just add the following line of code somewhere into that lisp (or any other lisp loaded automatically) - it only need be run once per drawing (so most of us would already have such somewhere, that's why these lisps don't include it):
    Code:
    (vl-load-com)
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

Page 1 of 3 123 LastLast

Similar Threads

  1. Attribute Tags
    By RobertAitken in forum VBA/COM Interop
    Replies: 5
    Last Post: 2010-06-11, 11:01 AM
  2. Re-use attribute tags
    By nancy.beulens in forum AutoCAD General
    Replies: 8
    Last Post: 2009-12-29, 02:23 PM
  3. If statement w/ attribute tags.
    By M. Kubitza in forum AutoLISP
    Replies: 2
    Last Post: 2009-11-17, 04:11 AM
  4. Renaming Tags
    By kenneth_white in forum AutoLISP
    Replies: 8
    Last Post: 2008-02-08, 09:52 PM
  5. Renaming Fields in Room Name Tags
    By Gardinine in forum Revit Architecture - General
    Replies: 3
    Last Post: 2003-09-04, 01:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •