Results 1 to 9 of 9

Thread: Duplicate Tag Names

  1. #1

    Default Duplicate Tag Names

    Hi

    I've got a problem with a title block I'm working with at the moment. It is on a couple hundred drawings through out the project.

    In the block I have duplicate tag names which is making it hard to change values of specific tags in the entire drawing set at once. There are 3 named "NUMBER, 3 named "NAME" and 4 named "EQUIPMENT".

    I've attached the block for reference.

    Does anyone have a handy bit of code that would change the tag names in the block with or without changing the values of the attributes. Not phased what the tag names become even if the names are simply incrementing the duplicate names numerically. i.e. the final tag names becoming name1 name2 etc.

    Any help would be appreciated since I'm new and fairly useless with AutoCAD programming
    Attached Files Attached Files

  2. #2
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    397

    Default Re: Duplicate Tag Names

    Daniel. if you woul've requested that particualr function on your previous post at CTT, i would have given you an answer.

    Anyhoo. I guess the more the better

    Code:
    (defun ReTagDup (bname Tag2Inc / bname Tag2Inc Blocks Found)
    (vl-load-com)      
    (setq TagLoop Tag2Inc)
    	(if (setq  Blocks (ssget "_X" (list '(0 . "INSERT")'(66 . 1)(cons 2 bname))))
                (progn
                	(repeat (sslength blocks)
                     (setq Found
    	                     (vl-remove-if-not
    	                                '(lambda (x)
    	                                      (assoc (car x) Tag2Inc))
    	                                (mapcar (function
    	                               (lambda (at)
    	                                     (list (vla-get-tagstring at)
    	                                           at)
    	                                     ))
    	                         (vlax-invoke (vlax-ename->vla-object (setq e (ssname Blocks 0)))
    	                               'Getattributes)
    	                         )))
                     (foreach itm (vl-sort Found '(lambda (j k)
                                          (< (car j)(car k))))
                                (setq inc (assoc (Car itm) TagLoop))
                                	(vla-put-tagstring (cadr itm) (strcat (car inc) (itoa (setq i (cadr inc)))))
                                	(setq TagLoop (subst (list (car inc) (setq i (1+ i))) inc TagLoop))
                                )
                          (setq TagLoop Tag2Inc)
                          (ssdel e blocks)
                          )
    		(vlax-for att (vla-item  (vla-get-blocks
    		                   (vla-get-ActiveDocument (vlax-get-acad-object)))
    		             bname)
    		      (if (and (eq (vla-get-objectname att)
    		                   "AcDbAttributeDefinition")
    		               (setq ren (assoc (vla-get-tagstring att) Tag2Inc)))
    		            (progn
    		                  (vla-put-tagstring
    		                        att
    		                        (strcat (car ren)
    		                                (itoa (setq i (cadr ren)))))
    		                  (setq Tag2Inc
    		                             (subst (list (car ren)
    		                                          (setq i (1+ i)))
    		                                    ren
    		                                    Tag2Inc))))
    		      )
                    (command "_attsync" "_Name" bname)
    		 )(princ "\n0 Objects Selected")
                )
    (princ)
          )
    Code:
    (ReTagDup "A3TITLE" '(("EQUIPMENT" 1)("NAME"  1)("NUMBER" 1)))
    Last edited by pbejse; 2012-06-20 at 07:33 AM.

  3. #3

    Default Re: Duplicate Tag Names

    Hi Pbesje

    Cheers again. I thought since the problem had changed (slightly) I would post a separate thread.

    I didn't read this thread again for a few days but I've trying to get it to work since. At first I would load the program in autocad and type the command retagdup but nothing would happen. I tried changing the code to have c:ReTagDup at the start but then it says there is an error: too few agruments. I then placed the second bit of code at the end of the program and it worked. All the duplicate tag names now have a number after them. Brillant.

    However, there is one thing I can't fix. Been at it all day. When I run the program all the font changes. Suddenly some text doesn't fit into the boxes and the actual title (LINE1, LINE2, LINE3) changes colour.

    Is there any way to keep the text the same?

    The rest works perfectly. Thanks

  4. #4

    Default Re: Duplicate Tag Names

    Sorry Hi Pbejse!

  5. #5
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    397

    Default Re: Duplicate Tag Names

    Quote Originally Posted by daniel.j.wright112877 View Post
    Hi Pbesje
    .... I then placed the second bit of code at the end of the program and it worked. All the duplicate tag names now have a number after them. Brillant.
    Thanks
    Good for you, glad you got it working


    Quote Originally Posted by daniel.j.wright112877 View Post

    However, there is one thing I can't fix. Been at it all day. When I run the program all the font changes. Suddenly some text doesn't fit into the boxes and the actual title (LINE1, LINE2, LINE3) changes colour.
    Is there any way to keep the text the same?
    I realize that (color reverting back to its origiinal state) when i run the code . I suspected alongthe way the attributes text properties were overriden thru EATTEDIT. insert the unmodified (prior to running the code above) A3TITLE in the drawing and you will see that original color and font. Even if you invoke attsync on the un-modiried block it will still revert to the original

    Thinking its a fluke i didnt pay too much atention to it.

    So how would want it? make the current text setting on your sample dwg as the default for the A3TITLE block?

  6. #6

    Default Re: Duplicate Tag Names

    Yeah I guess so. The idea would be to have the block look the same before and after running the code. The text settings in the sample dwg are the ones I'm after.

  7. #7
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    397

    Default Re: Duplicate Tag Names

    I realize that this is a repair job.

    So instead of a generic code , i modified (quick mod) the code to work exclusively for "A3TITLE".
    BTW: i noticed that the width varies from 0.9 to 1.0. as a compromise i use 0.95 width for all . (its your call)

    Code:
    (defun c:ReTagDup (/ fixa3 aDoc Tag2Inc TagLoop Blocks Found ren)
    (vl-load-com)
    (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))      
    (defun fixa3 (blk) 
          (vlax-for itm  blk
                (vla-put-StyleName itm "ISOCP")
                (vla-put-ScaleFactor itm 0.95)
                (if  (wcmatch (vla-get-tagstring itm) "LINE*")
                       (vla-put-color itm 2) )
                 )    
          )      
    (setq  Tag2Inc '(("EQUIPMENT" 1)("NAME"  1)("NUMBER" 1))
           TagLoop Tag2Inc)
    	(if (and (vl-every '(lambda (j)
                                  (tblsearch (Car j) (cadr j)))
                           '(("BLOCK" "A3TITLE")
                             ("STYLE" "ISOCP")
                             ))  
                  (setq  Blocks (ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "A3TITLE")))))
                (progn
                	(repeat (sslength blocks)
                     (setq Found
    	                     (vl-remove-if-not
    	                                '(lambda (x)
    	                                      (assoc (car x) Tag2Inc))
    	                                (mapcar (function
    	                               (lambda (at)
    	                                     (list (vla-get-tagstring at)
    	                                           at)
    	                                     ))
    	                         (vlax-invoke (vlax-ename->vla-object (setq e (ssname Blocks 0)))
    	                               'Getattributes)
    	                         )))
                     (foreach itm (vl-sort Found '(lambda (j k)
                                          (< (car j)(car k))))
                                (setq inc (assoc (Car itm) TagLoop))
                                	(vla-put-tagstring (cadr itm) (strcat (car inc) (itoa (setq i (cadr inc)))))
                                	(setq TagLoop (subst (list (car inc) (setq i (1+ i))) inc TagLoop))
                                )
                          (setq TagLoop Tag2Inc)
                          (ssdel e blocks)
                          )
    		(vlax-for att (setq a3 (vla-item  (vla-get-blocks
    		                   adoc) "A3TITLE"))
    		      (if   (setq ren (assoc (vla-get-tagstring att) Tag2Inc))
    		            (progn
    		                  (vla-put-tagstring att
    		                        (strcat (car ren)
    		                                (itoa (setq i (cadr ren)))))
    		                  (setq Tag2Inc
    		                             (subst (list (car ren)
    		                                          (setq i (1+ i)))
    		                                    ren
    		                                    Tag2Inc))))
    		      )
                    (fixa3 a3)
                    (command "_attsync" "_Name" "A3TITLE")
    		 )(princ "\n0 Objects Selected")
                )
    (vla-regen adoc acActiveViewport) 
    (princ)
          )

    EXCLUSIVELY for your block "A3TITLE"
    Last edited by pbejse; 2012-07-02 at 01:58 PM.

  8. #8

    Default Re: Duplicate Tag Names

    Hi pbejse

    Sorry for a slow reply. I thought I had subscribed to this thread.

    This code is perfect. No other other word for it.

    Thanks alot

  9. #9
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    397

    Default Re: Duplicate Tag Names

    Quote Originally Posted by daniel.j.wright112877 View Post
    Hi pbejse

    Sorry for a slow reply. I thought I had subscribed to this thread.

    This code is perfect. No other other word for it.

    Thanks alot
    You are welcome, Hope you learn from it.

    cheers

Similar Threads

  1. How to duplicate level names in tags
    By gregb in forum Revit Architecture - General
    Replies: 1
    Last Post: 2010-02-08, 11:45 AM
  2. Duplicate Level Names
    By Fatboy in forum Revit Architecture - General
    Replies: 12
    Last Post: 2009-02-05, 12:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •