• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

rename label (tag) block attribute

  • Thread starter Thread starter 77marco77
  • Start date Start date

77marco77

Guest
Good evening,
to change the name of the attribute label I found this lisp
HTML:
(defun c:c1 ( / oldtagname newtagname tagname ss x n blk att atts )
(vl-load-com)
(setq oldtagname "aukstis")
(setq newtagname "ag")
(setq ss nill)
(prompt "\npick all blocks to change: ")
(setq ss (ssget))
(if (and (/= oldtagname "")(/= newtagname "")(/= ss nil))
(progn
(setq x 0 n 0)
(repeat (sslength ss)
(setq blk (vlax-ename->vla-object (ssname ss x)))
(if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk))))
(progn
(setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
(foreach att atts
(setq tagname (strcase (vla-get-tagstring att))); tagname
(if (and (/= newtagname "")(= tagname oldtagname))
(progn
(vla-put-tagstring att newtagname)
(setq n (+ n 1))
); progn
); if
); foreach
); progn
); if
(setq x (+ x 1))
); repeat length ss
(alert (strcat "changed " (itoa n) " tagnames to: " newtagname))
); progn
); if
(princ)
); function

qui block attribute tag renameand do what he should.
I would like to be able to change it so that it completes the instructions even when they select between the others a block or an element that does not contain the label (at the moment by mistake and exits from the command).
if you could also ask the attribute to change and the new name without having to change each time the lisp would be the maximum, but I would be delighted with a help even only for the first part:)
 
Code:
(defun c:c1 (/oldtagname newtagname ss x n blk atts)
(vl-load-com)
(setq oldtagname (strcase (gestring)
Newtagname (strcase (getstring "\nnuova etichetta:")
n 0
)
(Probably all blocks to change)
(setq ss (ssget '(0. "insert"))))
(and ss (/= oldtagname)
(progn
(repeat (setq x)
(setq blk (vlax-ename->vla-object))
(if (vla-get-hasattributes :vlax-true)
(progn
(setq toss (vlax-safearray->list (vlax variant-value (vla-getattributes blk))))
(Foreach Elem Atts
(if (vla-get-tagstring elem) oldtagname
(progn
(vla-put-tagstring elem newtagname)
(Setq n (1+ n))
)
)
)
)
)
)
)
)
(alert (strcat "changed" (itoa n)" takennames to: "newtagname")
(Princ)
)
 
Hello confutatis, with this we are three that in a very short time help me!
the code does exactly what I wanted (I imagine the scene where you wrote it with the left hand while with the right drink the coffee and/or browse the newspaper. . )

Thank you so much!
 
Hello confutatis,
I only realized now that the code above does what I asked for in its time but not everything that I would need today. . .
I have to translate attributes tags so I have to change tags in block definitions and I'm looking for the way to change the tag name of a multiple block attribute simultaneously.
the modification should take place in the definition of the attribute (and not only in the reference), i.e. if I open the block with the block editor after launching the lisp above the tag should have the new name but unfortunately it is not so.
Moreover if I do sincatt deletes the changes and reports tags and attributes to the original name and definition of the block then losing also the information placed in the attribute.

I would have found this code (I don't know where...):
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
;;;;;;; comando (renattrib "testblk" "oldtag" "newtag")
that does what I would need but to make it go I have to give the command to the prompt for every single block and for every single attribute.
would there be a way to speed up the procedure?
thanks in advance
 
Yes, there are altogether 6358 blocks, with a variable number of attributes between 6 and 28. all the blocks have these 6 tags always equal, about 80% of the blocks has additional 6 equal attributes and the remaining 20% has additional number varying between 2 and 14 (also equal).
 
I don't know if that was what you wanted... .
Code:
;;; rename attributes
(defun c:renatt (/ blocks bo eo ao)
  ;; get blocks collection in current drawing
  (setq oldtag (strcase (getstring "\nold tag: ")))
  (setq newtag (strcase (getstring "\nnew tag: ")))
  (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")
              (= (vla-get-tagstring eo) oldtag)
         ) ;_ end of and
         (vla-put-tagstring eo newtag) ;change to new name
        )
       ) ;_ end of cond
    ) ;_ end of vlax-for
  ) ;_ end of vlax-for
  (vl-cmdf "_attsync" "n" "*")
 (princ)
) ;_ end of defun
 
Last edited:
code does exactly what it should (and at the speed of light!).

what I really like about your codes is the "simplicity" and elegance that make them look (and unfortunately only look) a teeny game.

Thank you so much!
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top