Jump to content

Lisp to change att TAG name(Not Value) with up to 13 old - new names.


callvey

Recommended Posts

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • Tharwat

    13

  • callvey

    11

  • johmmeke

    3

  • BIGAL

    2

Top Posters In This Topic

  • 3 months later...

first of all, sorry to respond on a old thread.

 

I use the routine from Tharwat in #9

 

When i use this in acad 2014, all my attribute values are set back to default. Do i have a setting wrong?

This has been working really fine in acad 2012.

 

Greetz John

Edited by johmmeke
Link to comment
Share on other sites

I modified the routine in post #9 since that is the one you are using and added a few lines of codes to reset the same text strings of block's attributes that are in a drawing . try it and let me know .

 

(defun c:Test (/ *error* cmd l a lst f h nm bks v cmd ss)
 ;;    Tharwat 07. 07 . 2014        ;;
 (defun *error* (msg)
   (if cmd
     (setvar 'CMDECHO cmd)
   )
   (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
     (princ msg)
     (princ (strcat "*** Error : " msg "***"))
   )
   (princ)
 )
 (or doc
     (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 )
 (setq cmd (getvar 'CMDECHO)
       l   '(("AREA1" . "AREA13")
             ("AREA2" . "AREA14")
             ("AREA3" . "AREA15")
             ("AREA4" . "AREA16")
             ("AREA5" . "AREA17")
             ("AREA6" . "AREA18")
             ("AREA7" . "AREA19")
             ("AREA8" . "AREA20")
            )
 )
 (if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
   ((lambda (i / sn f)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (foreach tg (vlax-invoke
                      (vlax-ename->vla-object sn)
                      'GetAttributes
                    )
          (if (setq f (assoc (strcase (vla-get-tagstring tg)) l))
            (setq lst
                   (cons (list sn (cdr f) (vla-get-textstring tg)) lst)
            )
          )
        )
      )
    )
     -1
   )
 )
 (if lst
   (progn
     (vlax-for x (vla-get-blocks doc)
       (if (and (eq :vlax-false (vla-get-isxref x))
                (eq :vlax-false (vla-get-islayout x))
           )
         (vlax-for o x
           (if
             (and (eq (vla-get-objectname o) "AcDbAttributeDefinition")
                  (setq a (assoc (strcase (vla-get-tagstring o)) l))
             )
              (progn (vla-put-tagstring o (cdr a))
                     (if (not (member (setq nm (vla-get-name x)) bks))
                       (setq bks (cons nm bks))
                     )
              )
           )
         )
       )
     )
     (setvar 'CMDECHO 0)
     (mapcar '(lambda (n) (command "_.attsync" "_Name" n)) bks)
     (setvar 'CMDECHO cmd)
     (foreach x lst
       (foreach tg (vlax-invoke
                     (setq v (vlax-ename->vla-object (car x)))
                     'GetAttributes
                   )
         (if
           (and (eq (strcase (vla-get-tagstring tg)) (strcase (cadr x)))
                (vlax-write-enabled-p v)
           )
            (vla-put-textstring tg (caddr x))
         )
       )
     )
   )
 )
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

;) thank you

 

works perfect again.

This is a great help me, i often get drawing where the tag name's are not consistant.

 

Thx again for the help,

 

JOhn

Link to comment
Share on other sites

;) thank you

 

works perfect again.

This is a great help me, i often get drawing where the tag name's are not consistant.

 

Thx again for the help,

 

JOhn

 

Excellent . You're welcome John and I am really happy to help . :)

Link to comment
Share on other sites

Tharwat, one thing i come across is that the routine is not working on dynamic block's.

This is not so import to me, just to let u know.

 

John

Link to comment
Share on other sites

Tharwat, one thing i come across is that the routine is not working on dynamic block's.

This is not so import to me, just to let u know.

 

John

 

That is correct , and I do know that John :)

 

Simply due to the name of the dynamic block that can not be retrieved by the function vla-get-name which strongly supports my saying and would fail with Dynamic Blocks ;)

Link to comment
Share on other sites

Tharwat,

Although You can get the dynamic block by name, you can change it's tag name, but it doesn't effect its "child" dynamic blocks, because they are independent from their "parent".

If you want to change tag name, you have to change every "child" block, not only their "parent". Try this:

(defun c:test(/ l en tm)
 (setq l   '(("AREA1" . "AREA13")
             ("AREA2" . "AREA14")
             ("AREA3" . "AREA15")
             ("AREA4" . "AREA16")
             ("AREA5" . "AREA17")
             ("AREA6" . "AREA18")
             ("AREA7" . "AREA19")
             ("AREA8" . "AREA20")
            )
 )
 (foreach en (vl-remove-if 'listp
	(mapcar 'cadr (ssnamex (ssget "X" '((0 . "INSERT") (66 . 1))))))
    (while (and (setq en (entnext en))
	 (/= (cdr (assoc 0 (entget en))) "SEQEND"))	
       (if (and (= (cdr (assoc 0 (entget en))) "ATTRIB")
	 (setq tm (assoc (cdr (assoc 2 (entget en))) l)))
  (entmod (subst (cons 2 (cdr tm)) (assoc 2 (entget en)) (entget en))))
    )
 ) (princ)
)

Hope this can help.

Link to comment
Share on other sites

The difference is you try to catch the block by name and to use the "attsync" command of cad, it change blocks to their default properties, such as color,..

My code is just surfing through each block, change only its tag name, and leave other properties unchanged.

Link to comment
Share on other sites

The difference is you try to catch the block by name and to use the "attsync" command of cad, it change blocks to their default properties, such as color,..

My code is just surfing through each block, change only its tag name, and leave other properties unchanged.

 

Correct , and I know that I took the long way to reach the destination but it is okay since that we got what we want .

 

But you may need to add a few codes to change the PARENT blocks' tag names as well as the CHILDREN 's did . ;)

Link to comment
Share on other sites

  • 4 years later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...