Author Topic: Renaming attribute tag via script  (Read 10216 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
Re: Renaming attribute tag via script
« Reply #15 on: June 12, 2007, 10:00:19 AM »
CAB I was thinking that too. I have inserted our revision blocks into a drawing and also included the lisp rotine we are now using to update the rev 1 block. we used to have to update every page one by one and this one works across multiple layouts. Originally both of the tag names were REV_DATE and the uptoday or today is date formatting code from our acad.lsp. I was having conflicts if I opened up an old file and accidently used the new tool. Now we have an old and new update tool and I'd like to eliminate it by converting all of the old tag names to the new but retain the job info. Am I making sense, I hope so. I just wanted to tell the whole story in case someone is just jumping in at this point.

Try this

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #16 on: June 12, 2007, 10:04:39 AM »
My problem was that I updated the block but not the inserts, so new inserts are correct but old ones still have the wrong tag.
Just tried Ron's & it worked fine and his honers locked layers.

Try his again.
Code: [Select]
(rjp-replacetagname '(("REV_DATE" . "TestTag")("NEW_TAG" . "TestTag")("TestTag" . "Xtag")))You get an error?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Renaming attribute tag via script
« Reply #17 on: June 12, 2007, 10:17:11 AM »
OK we will try to get his working. I tried this and get unknown command when i type replacetagname, why?

Code: [Select]
(defun replacetagname (lst / lays ss)
  (setq lays (vla-get-layers
       (vla-get-activedocument (vlax-get-acad-object))
     )
ss   (ssget "x" '((0 . "INSERT") (66 . 1)))
  )
  (if ss
    (progn
      (setq ss (mapcar 'vlax-ename->vla-object
       (vl-remove-if
'listp
(mapcar 'cadr (ssnamex ss))
       )
       )
      )
      (mapcar
'(lambda (b)
   (if (eq (vla-get-lock (vla-add lays (vla-get-layer b)))
   :vlax-false
       )
     (progn
       (mapcar
'(lambda (a)
    (mapcar '(lambda (c)
       (if (eq (strcase (car c))
       (strcase (vla-get-tagstring a))
   )
(vla-put-tagstring a (cdr c))
       )
     )
    lst
    )
  )
(vlax-invoke b 'getattributes)
       )
     )
   )
)
ss
      )
    )
  )
  (princ)
)
(replacetagname '(("REV__DATE" . "TestTag")("NEW_TAG" . "TestTag")("TestTag" . "Xtag")))

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #18 on: June 12, 2007, 10:32:38 AM »
You have to paste this at the command line:
Code: [Select]
(replacetagname '(("REV__DATE" . "TestTag")("NEW_TAG" . "TestTag")("TestTag" . "Xtag")))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #19 on: June 12, 2007, 10:50:27 AM »
OK, here is my corrected code. Honers locked layers. Note that this is the layer the attribute is on & not layer the insert is on.
Code: [Select]
(defun c:TagReplace (/ blkname blkobjs)
  ;;  replace attr Tag in Inserts & Block
  (defun ReplaceBlockTag (OldNames  ; list of old tag names
                          NewName   ; string - New tag name
                          objlst    ; lit of Inserts in DWG
                          / atts idx obj)
    (vl-load-com)
    (setq OldNames (mapcar 'strcase OldNames))
    ;;  Update Inserts
    (foreach obj objlst
      (foreach att (vlax-invoke obj 'getattributes)
        (if (vl-position (strcase (vla-get-tagstring att)) OldNames)
          (setq err (vl-catch-all-apply 'vla-put-tagstring (list att NewName)))))
    )
    (if (vl-catch-all-error-p err)
      (princ "\nFailed - Attr on Locked layer.")
      ;;  step through the block definition
      (vlax-for blkobj (vla-item
                         (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
                         (vla-get-name (car objlst))
                       )
        (if (and (vlax-property-available-p blkobj 'tagstring)
                 (vl-position (strcase (vla-get-tagstring blkobj)) OldNames)
            )
          (vla-put-tagstring blkobj NewName)
        )
      )
    )
  )

  (setq blkname "REVTITLE")
  (if (setq ss (ssget "X" (list '(0 . "INSERT") (cons 2 blkname) '(66 . 1))))
    (progn
      (setq blkobjs (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))
      (ReplaceBlockTag '("REV_DATE" "NEW_TAG" "Tag1") "Tag2" blkobjs)
    )
    (princ "\nNo Inserts Found.")
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Renaming attribute tag via script
« Reply #20 on: June 12, 2007, 10:52:47 AM »
Ah ok My result was Xtag so it does work. Now that it works from the command line i can just put this is my script right. So how do I specify multiple blocks names or do I not need to?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #21 on: June 12, 2007, 11:01:30 AM »
Mine will not handle multiple block names.
Ron's code only looks at the tag names so block names don't come into play.
Unless there is a block with matching name you don't want changed.
Also note that Ron's honers the locked layer of the Insert, unlike mine.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #22 on: June 12, 2007, 11:06:42 AM »
Hold the presses.
I just caught that Ron's doesn't update the Block Definition, so if you insert another of that block
it will have the old tag name. Let's see if Ron wants to add that.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Renaming attribute tag via script
« Reply #23 on: June 12, 2007, 11:19:46 AM »
CAB i have uploaded an old drawing to illustrate another potential problem. The tags in the old blocks both have the same name but the new block has different names. I don't know how I would specify which is which. I'll ask maybe a stupid question but do the attributes really need to have different names to use the new routine. I'm trying to figure out which would be the easier to change? Have a look

Old Method

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #24 on: June 12, 2007, 12:08:11 PM »
Having attributes with the same tag is a problem with both of our routines.
Additional programing is needed to specify which attribute needs to be changed else all matching attributes will be changed.

What problem are you experiencing with using 2 underscore characters?

To specify specify which is which.
You would need to specify first or last, or 1 or 2, etc.
« Last Edit: June 12, 2007, 12:09:57 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #25 on: June 12, 2007, 12:14:06 PM »
I see that c:Rec1 Updates the date attributes on all tabs.
To be more precise it updates the last block added to that tab & ignores the blocks added prior to the last one.
 
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Renaming attribute tag via script
« Reply #26 on: June 12, 2007, 01:44:11 PM »
not sure i follow you cab but basically i want all of our drawings old or new to update the same way. now we are having conflicts between the old and new blocks as we have combonations of old and new revisions. Yikes I think I've created a monster here. I just got so annoyed with having to update each layout but dealing with the legacy files is the real PITA. I keep getting users telling me that the update is not working and it's because they are trying to use the wrong tool for the wrong block and it's a mess.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #27 on: June 12, 2007, 02:01:15 PM »
OK, after some snooping the deference is that one string has 5 characters & the other has 8 characters.
Change REV_DATE with 8 characters  to  REV4__DATE

Change REV_DATE with 5 characters  to  REV4__DATE_ABBRV

Is that what you want to do?

Is REV_DATE the only old tag or are there others like REV__DATE ?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Renaming attribute tag via script
« Reply #28 on: June 12, 2007, 03:33:56 PM »
CAB Here is a breakdown of the block names and associated tags

Block name and Tags for old blocks:

Revtitle   REV_DATE
Revtitl2   REV2_DATE
Revtitl3   REV3_DATE
Revtitl4   REV4_DATE

Block name and Tags for new blocks:

Revtitle   REV__DATE (Bottom)
Revtitle   REV__DATE__ABBRV (Top)
Revtitl2   REV2__DATE (Bottom)
Revtitl2   REV2__DATE__ABBRV (Top)
Revtitl3   REV3__DATE (Bottom)
Revtitl3   REV3__DATE__ABBRV (Top)
Revtitl4   REV4__DATE (Bottom)
Revtitl4   REV4__DATE__ABBRV (Top)



ELOQUINTET

  • Guest
Re: Renaming attribute tag via script
« Reply #29 on: June 13, 2007, 08:53:41 AM »
so cab any thoughts on how this could be done. i was reading through the original post as saw mention of doing it by order. There are 2 attributes of the same name in the old blocks but they occur in a certain order everytime so in effect the first one could be changed to this and the second to that, no?