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

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #30 on: June 13, 2007, 09:07:53 AM »
It will take a specialised routine and it can be done using the order or the length of the text string "06/21" vs "06/21/06"
I don't have time to play with it today but if no one steps up I may have time tomorrow.
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 #31 on: June 13, 2007, 09:40:10 AM »
that's cool cab it's no rush, i appreciate anything you can do. I just need to have a way to eventually clean this mess up. Thanks man

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Renaming attribute tag via script
« Reply #32 on: June 13, 2007, 08:44:54 PM »
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.


CAB,

How would I update the block definition? I'm not sure where to start.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #33 on: June 13, 2007, 09:12:09 PM »
Maybe this?
Code: [Select]
(defun rjp-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 (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)
       )
               ;;  update block def  -------------------
      (vlax-for blkobj (vla-item
                         (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
                         (vla-get-name b)
                       )
    (mapcar '(lambda (c)
       (if (and (vlax-property-available-p blkobj 'tagstring)
                                        (eq (strcase (car c))
                                            (strcase (vla-get-tagstring blkobj))
   ))
(vla-put-tagstring blkobj (cdr c))
       )
     )
    lst
    )
       
       ) ; ----------------
     )
   )
)
ss
      )
    )
  )
  (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.

Fatty

  • Guest
Re: Renaming attribute tag via script
« Reply #34 on: June 14, 2007, 05:48:30 AM »
Hi Alan
I use
Code: [Select]
(vlax-property-available-p blkobj 'tagstring T)when i want to change tagstring property
Is it correct?

~'J'~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Renaming attribute tag via script
« Reply #35 on: June 14, 2007, 07:50:40 AM »
Hey Fatty,
You have led me to a flaw in the code.
Other than a Locked layer, why would the property be unavailable?

I did some more testing & if the layer the attribute is on is locked it will fail.
So another test is needed to prevent that failure.

But what other condition would prevent the tag replacement?

Bad tag name is the only thing that comes to mind. Anyone know of another?
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 #36 on: June 14, 2007, 08:53:33 AM »
wow you guys have been busy this morning. I have encountered some instances where these attributes are on a locked layer. To safeguard against this I was just thinking of unlocking all the layers first via script. We don't use layers that much here so it should be on a specific layer but it is not guarenteed. I know it is good practice as a coder to cover all the bases but like I said this is primarily being used for housekeeping purposes. Most jobs done before this year are already installed and will not be revised so there will be no conflict but I'd like to retag as many as I can anyway. I'll check back in a little bit thanks guys

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Renaming attribute tag via script
« Reply #37 on: June 14, 2007, 03:08:58 PM »
Thanks CAB...I see the light now. :)

I updated to catch if the attribute is on a locked layer.

Code: [Select]
(defun rjp-replacetagname (lst / blkobj 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 (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
   (and (eq (strcase (car c))
    (strcase (vla-get-tagstring a))
)
(eq (vla-get-lock
      (vla-add lays (vla-get-layer a))
    )
    :vlax-false
)
   )
    (vla-put-tagstring a (cdr c))
)
       )
      lst
    )
  )
(vlax-invoke b 'getattributes)
       )
       (vlax-for blkobj (vla-item
  (vla-get-blocks
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
  (vla-get-name b)
)
(mapcar
   '(lambda (c)
      (if
(and
  (vlax-property-available-p blkobj 'tagstring)
  (eq (strcase (car c))
      (strcase (vla-get-tagstring blkobj))
  )
)
(vla-put-tagstring blkobj (cdr c))
      )
    )
   lst
)
       )
     )
   )
)
ss
      )
    )
  )
  (princ)
)
(rjp-replacetagname '(("tagnametoreplace" . "newtagname")))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: Renaming attribute tag via script
« Reply #38 on: June 18, 2007, 08:59:30 AM »
I thought the main thing we were trying to figure out was how to distinguish which one of the old tags to change to what. I think the only way would be to have it read the number of characters as CAB suggested. One tag will read as Month/Day and the other Month/Day/Year so I think it would be best to do something like look at the value and if it contains more than 5 characters it should be changed to REV__DATE and if it is 5 or less it should be changed to REV__DATE__ABBRV. or like CAB said it could be based on 5 or 8 characters as well. Anybody have time to look into this?