Jump to content

Change Tag names in attributed block


77shawn

Recommended Posts

I have a drawing that was exported from Inventor, and now the Tag names in the attributed title block all have an extra "_001" added to them. I can edit them in AutoCAD useing the Block Attribute Manager", but I have hundreds up files to edit. Has anyone had this problem, or know any way to write a script to change these. The block has 47 Tags (not the vaules) that need to be edited.

Link to comment
Share on other sites

I posted this to the Autodesk discussion group long ago, but now it's finally come up again and I need to fix this.

Below is a screen shot, basicly I need the Tag to be the same as the Prompt if that helps. Don't know what easier, strip the "_001" off the Tag names, or have it just match all Tag names to the Prompt names.

 

Any help would be great!!!

Thanks!!

 

 

HEAD-090208.jpg

Link to comment
Share on other sites

I normally wait and hope Lee or one of the other LISP gurus passes through or a mod comes by and moves it to that forum. I'll see if a mod is around.....

Link to comment
Share on other sites

I'd try something like this:

 

[b][color=BLACK]([/color][/b]defun rt_rstr [b][color=FUCHSIA]([/color][/b]fst old new / tmp p[b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]= [b][color=MAROON]([/color][/b]type fst[b][color=MAROON])[/color][/b] 'STR[b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]= [b][color=MAROON]([/color][/b]type old[b][color=MAROON])[/color][/b] 'STR[b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]= [b][color=MAROON]([/color][/b]type new[b][color=MAROON])[/color][/b] 'STR[b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]setq p 1[b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]repeat [b][color=MAROON]([/color][/b]strlen fst[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]= old [b][color=BLUE]([/color][/b]substr fst p [b][color=RED]([/color][/b]strlen old[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                 [b][color=GREEN]([/color][/b]setq tmp [b][color=BLUE]([/color][/b]strcat [b][color=RED]([/color][/b]substr fst 1 [b][color=PURPLE]([/color][/b]1- p[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                                   new
                                   [b][color=RED]([/color][/b]substr fst [b][color=PURPLE]([/color][/b]+ p [b][color=TEAL]([/color][/b]strlen old[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq p [b][color=GREEN]([/color][/b]1+ p[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]if tmp tmp fst[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

[b][color=BLACK]([/color][/b]defun c:retag [b][color=FUCHSIA]([/color][/b]/ bad i ss en an ad at nt[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq bad [color=#2f4f4f]"_001"[/color][b][color=FUCHSIA])[/color][/b]  [color=#8b4513];;;CASE SENSITIVE[/color]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq i -1
           ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 [b][color=PURPLE]([/color][/b]entget an[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]setq ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b]
                          at [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 2 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                          an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                    [b][color=GREEN]([/color][/b]and [b][color=BLUE]([/color][/b]wcmatch at [b][color=RED]([/color][/b]strcat [color=#2f4f4f]"*"[/color] bad [color=#2f4f4f]"*"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                         [b][color=GREEN]([/color][/b]setq nt [b][color=BLUE]([/color][/b]rt_rstr at bad [color=#2f4f4f]""[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                         [b][color=GREEN]([/color][/b]entmod [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 2 nt[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 2 ad[b][color=RED])[/color][/b] ad[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.REGENALL"[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

It doesn't change the BLOCK table definition but does change the INSERT ATTRIB data. -David

Link to comment
Share on other sites

I wrote this a while back, not sure if it helps also, will make the TagString the same as the PromptString.

 

(defun c:attupd (/ ss sel doc lst tag)
 (vl-load-com)

 (if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
   (progn
     (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                               (setq doc (vla-get-ActiveDocument
                                           (vlax-get-acad-object)))))
       (vlax-for Sub (vla-item
                       (vla-get-Blocks doc)
                         (vla-get-Name Obj))
         
         (if (eq "AcDbAttributeDefinition"
               (vla-get-ObjectName Sub))
           (setq lst
             (cons
               (cons
                 (vla-get-TagString Sub)
                   (vl-list->string
                     (subst 95 32
                       (vl-string->list
                         (vla-get-PromptString Sub))))) lst))))
       
       (foreach att (vlax-invoke Obj 'GetAttributes)
         (if (setq tag (assoc (vla-get-TagString att) lst))
           (vla-put-TagString att (cdr tag))))
       
       (setq lst nil))
     
     (vla-delete sel))
   
   (princ "\n** No Attributed Blocks Found **"))
 (princ))
               

Link to comment
Share on other sites

Sweet!! I've been looking for this for two years!

I used Lee Mac's code.

I can't believe my eyes, but it worked!!!! Thanks so much!!

I wish I had found this site sooner.

 

Thanks again.

Link to comment
Share on other sites

  • 4 months later...

If you ever want to change the tag names (not the values) for attributed blocks, you can use the following, creating a list of old & new tag names.

 

(defun c:attr_rename_list (  / x_en enn edd ss slen ix atnam 
          namelist hit blk_ent
          matchname newed x) 
 ; Process all block instances on active drawing. Check each 
 ; attribute for match on first element in list below. On any
 ; match, rename the attribute to the new name given in the
 ; second element. 

 ; ***********   ATTRIBUTE OLD versus NEW names list   ******************
 (setq namelist (list
     ; list old name and new name. Old name can contain wild cards.
     (list "OLD_TAG_NAME#1" "NEW_TAG_NAME#1")  ; list old name and new name. 
     (list "OLD_TAG_NAME#2" "NEW_TAG_NAME#2")
     (list "OLD_TAG_NAME#3" "NEW_TAG_NAME#3")
     (list "OLD_TAG_NAME#4" "NEW_TAG_NAME#4")
     (list "OLD_TAG_NAME#5" "NEW_TAG_NAME#5")
 ) )  
 ; **********************************************************************

 ; Extract selection set of all block inserts on active drawing  
 (setq ss (ssget "_X" '((0 . "INSERT"))))
 (if (/= ss nil)
   (progn
     (setq slen (sslength ss))
     (setq ix 0)
     (while (< ix slen)
       (setq blk_ent (ssname ss ix)) ; get next block insert to process        
       (setq ix (1+ ix)) ; increment for next time
       (setq enn (entnext blk_ent)) 
       (setq edd (entget enn))  
       (while (AND enn (/= (cdr (assoc 0 edd)) "SEQEND") 
                           (/= (cdr (assoc 0 edd)) "INSERT") )
         (if (= (cdr (assoc 0 edd)) "ATTRIB")
           (progn
             (setq atnam (cdr (assoc 2 edd)))
             (setq hit nil)
             (foreach x namelist
               (if (not hit)
                 (progn ; no match yet, keep processing
                   (setq matchname (car x))                
                   (if (wcmatch atnam matchname) 
                     (progn ; found exact match or wild-card match
                       ; Change name now. Substitute in new name.
                       (setq newed (subst (cons 2 (cadr x)) (assoc 2 edd) edd)) 
                       (entmod newed) ; update the title block instance
                       (entupd blk_ent) 
                       (princ "\n")
                       (princ atnam)
                       (princ " --> ")
                       (princ (cadr x))
                       (setq hit 1) ; flag that found
               ) ) ) )
             )
           )
         )     
         ; go to next sub ent in block instance and loop back up
         (if (setq enn (entnext enn)) (setq edd (entget enn))) 
     ) ) 
     (setq ss nil) ; release the selection set
   )
 )
 (princ) ; prettier
)

Link to comment
Share on other sites

  • 2 years later...

I posted this in another thread, although i dont know if that was the correct place.

 

anyways, does anyone know of a lisp that will change multiple and different blocks at once. i have tried the GATTE command, but will only let me select one block at a time. I have a drawing full of furniture with various text attribute tags on them and i want to change them all to blank.

Link to comment
Share on other sites

  • 4 years later...

Lee,

 

I've tried to make this work for the last 4 hours. I want to use this code to analyze a file full of blocks, look for an attribute definition with a certain prompt, change the prompt, and make the attribute position locked.

 

I've had no joy in doing this, any suggestions?

 

I wrote this a while back, not sure if it helps also, will make the TagString the same as the PromptString.

 

(defun c:attupd (/ ss sel doc lst tag)
 (vl-load-com)

 (if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
   (progn
     (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                               (setq doc (vla-get-ActiveDocument
                                           (vlax-get-acad-object)))))
       (vlax-for Sub (vla-item
                       (vla-get-Blocks doc)
                         (vla-get-Name Obj))
         
         (if (eq "AcDbAttributeDefinition"
               (vla-get-ObjectName Sub))
           (setq lst
             (cons
               (cons
                 (vla-get-TagString Sub)
                   (vl-list->string
                     (subst 95 32
                       (vl-string->list
                         (vla-get-PromptString Sub))))) lst))))
       
       (foreach att (vlax-invoke Obj 'GetAttributes)
         (if (setq tag (assoc (vla-get-TagString att) lst))
           (vla-put-TagString att (cdr tag))))
       
       (setq lst nil))
     
     (vla-delete sel))
   
   (princ "\n** No Attributed Blocks Found **"))
 (princ))
               

Link to comment
Share on other sites

I want to use this code to analyze a file full of blocks, look for an attribute definition with a certain prompt, change the prompt, and make the attribute position locked.

 

Consider the following code, changing the highlighted variable values as appropriate:

(defun c:fixprompt ( / new old )
   (setq old [color=red]"Old Prompt"[/color]
         new [color=red]"New Prompt"[/color]
   )
   (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (if (= :vlax-false (vla-get-isxref blk) (vla-get-islayout blk))
           (vlax-for obj blk
               (if
                   (and
                       (= "AcDbAttributeDefinition" (vla-get-objectname obj))
                       (= (strcase old) (strcase (vla-get-promptstring obj)))
                       (vlax-write-enabled-p obj)
                   )
                   (progn
                       (vla-put-promptstring obj new)
                       (vla-put-lockposition obj :vlax-true)
                   )
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Note that you will need to use ATTSYNC to apply the Locked Position property to all references of the attribute in the drawing.

Link to comment
Share on other sites

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...