batch change title block

batch change title block

mruPRQUJ
Advocate Advocate
2,670 Views
46 Replies
Message 1 of 47

batch change title block

mruPRQUJ
Advocate
Advocate

Hello,

There are lots of drawing title blocks that need to be changed.  One of them is the previous attribute is blank for some DWGs title blocks. The value needs to be added. Another one is revision, like 2A, 3A, 5A, and 10A. They need to be changed to 2B, 3B, 5B, and 10B. Could you please provide some advice? Thank you very much in advance. Michael

0 Likes
Accepted solutions (3)
2,671 Views
46 Replies
Replies (46)
Message 2 of 47

Sea-Haven
Mentor
Mentor

There are numerous examples out there for what you want, most have to have some customisation done to suit YOUR needs. 

 

Re adding title block details I did a fill in 1 title block and all details are copied to the title block in all other layouts. Its a global code so should work for any block in multiple layouts, Stuff like "sheet x of Y" generally needs a custom approach is it 1 or 2 attributes. 

 

The revisions A to B is a custom request, and can be simple or complicated.

 

With no sample dwg to look at can not really comment on how much is involved other than its sounds like 2, 3 or 4 programs.

 

0 Likes
Message 3 of 47

Moshe-A
Mentor
Mentor

@mruPRQUJ  hi,

 

give this a try.

 

note:

it will replace the last 'A' to 'B' and 'a' to 'b'

and the last

'B' to 'A' and 'b' to 'a'

 

enjoy

Moshe

 

 

 

 

(defun c:ASet (/ chgtxt ; local function
	         ss attributes val)

 (defun chgtxt ()
  (cond
   ((= (car (reverse (vl-string->list val))) 65)
    (vl-string-subst "B" "A" val)
   )
   ((= (car (reverse (vl-string->list val))) 97)
    (vl-string-subst "b" "a" val)
   )
   ((= (car (reverse (vl-string->list val))) 66)
    (vl-string-subst "A" "B" val)
   )
   ((= (car (reverse (vl-string->list val))) 98)
    (vl-string-subst "a" "b" val)
   )
  ); cond
 ); chgtxt

  
 (setq ss (ssget '((0 . "insert") (66 . 1))))

 (vlax-for AcDbEntity (vla-get-activeSelectionSet (vla-get-activedocument (vlax-get-acad-object)))
  (if (and
	(eq (vla-get-objectName AcDbEntity) "AcDbBlockReference")
	(eq (vla-get-hasAttributes AcDbEntity) :vlax-true)
      )
   (progn 
    (foreach AcDbAttrib (setq attributes (vlax-invoke AcDbEntity 'getAttributes))
     (setq val (vla-get-textString AcDbAttrib))

     (cond
      ((wcmatch val "#[AaBb]")
       (vla-put-textString AcDbAttrib (chgtxt))
      )
      ((wcmatch val "##[AaBb]")
       (vla-put-textString AcDbAttrib (chgtxt))
      )
     ); cond
    ); foreach

    (foreach AcDbAttrib attributes
     (vlax-release-object AcDbAttrib) 
    )
   ); progn 
  ); if
  (vlax-release-object AcDbEntity)
 ); vlax-for

 (princ) 
)

 

0 Likes
Message 4 of 47

mruPRQUJ
Advocate
Advocate

Thank you very much all of you. I am sorry I did not say it clearly. There is more info below.

1. For the first scenario, the block name is BCH-X-BORD-Dxxx, the current attribute value could be different, and the new value are below,

tag           TITLE_LINE_1                    DATE        DESIGNED_BY      INDEPENDENT_CHK    DRAFTED_BY   DRAFTING_CHECK   

value        DMR SUBSTATION      2023FEB25    K. BAINS                R. CLELLAND                  M. RU                K. BAINS

 

TAG         INSPECTED_BY                 REVIEWED_BY             ACCEPTED_BY

VALUE     BLANK                                BLANK                           BLANK

 

2. For the second scenario, the current value is 2A, 3A, 5A. The new value is 2, 3, 5 or 2B, 3B, 5B. There are two blocks. One block name is BCH-X-BORD-Dxxx, tag is REV_#.

Another block name is BCH-X-BORD-REVI, tag is R_NO.

Thanks again, your help is great and much appreciated. 

0 Likes
Message 5 of 47

Moshe-A
Mentor
Mentor

@mruPRQUJ,

 

check this

 

enjoy

moshe

 

 

(defun c:ASet (/ format_date chgtxt ; local function
	         data^ ss attributes tag val nv)

 (defun format_date (/ mon date)
  (setq mon '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEP" "OCT" "NOV" "DEC"))
  (setq date (rtos (fix (getvar "cdate")) 2 0))

  (strcat (substr date 1 4) (nth (1- (atoi (substr date 5 2))) mon) (substr date 7 2))	 
 ); format_date


 (defun chgtxt (s)
  (cond
   ((wcmatch tag "REV_#,REV_##")  
    (cond
     ((= (car (reverse (vl-string->list val))) 65)
      (vl-string-subst "B" "A" s)
     )
     ((= (car (reverse (vl-string->list val))) 97)
      (vl-string-subst "b" "a" s)
     )
    ;| ((= (car (reverse (vl-string->list val))) 66)
      (vl-string-subst "A" "B" s)
     )
     ((= (car (reverse (vl-string->list val))) 98)
      (vl-string-subst "a" "b" s)
     ) |;
    ); cond
   ); case
   ((eq tag "R_NO")
    (repeat 2 
     (foreach c '("A" "a" "B" "b") 
      (setq s (vl-string-right-trim c s))
     )
    ); repeat
   ); case
  ); cond
 ); chgtxt


 ; here start c:ASet
 (setq data^ '(("TITLE_LINE_1"    . "DMR SUBSTATION")
	       ("DATE"            . "2023FEB25")
	       ("DESIGN_BY"       . "K. BAINS")
	       ("INDEPENDENT_CHK" . "R. CLELLAND")
	       ("DRAFTED_BY"      . "M. RU")
	       ("DRAFTING_CHECK"  . "K. BAINS")
	       ("INSPECTED_BY"    . "")
	       ("REVIEWED_BY"     . "")
	       ("ACCEPTED_BY"     . "")
	      )
 ); setq
  
 (setq ss (ssget '((0 . "insert") (66 . 1))))

 (vlax-for AcDbEntity (vla-get-activeSelectionSet (vla-get-activedocument (vlax-get-acad-object)))
  (if (and
	(eq (vla-get-objectName AcDbEntity) "AcDbBlockReference")
	(wcmatch (strcase (vla-get-name AcDbEntity)) "BCH-X-BORD-D###,BCH-X-BORD-REVI,TEST")
	(eq (vla-get-hasAttributes AcDbEntity) :vlax-true)
      )
   (progn 
    (foreach AcDbAttrib (setq attributes (vlax-invoke AcDbEntity 'getAttributes))
     (setq tag (strcase (vla-get-tagString AcDbAttrib)))
     (setq val (vla-get-textString AcDbAttrib))

     (cond
      ((setq item (assoc tag data^))
       (if (eq tag "DATE")
        (vla-put-textString AcDbAttrib (format_date))
        (vla-put-textString AcDbAttrib (cdr item))
       ); if
      ); case
      ((wcmatch tag "REV_#,REV_##,R_NO")

       (cond
        ((and
	   (wcmatch val "#[AaBb]")
	   (setq nv (chgtxt val))
	 )
         (vla-put-textString AcDbAttrib nv)
        ); case
        ((and
	   (wcmatch val "##[AaBb]")
	   (setq nv (chgtxt val))
	 )
         (vla-put-textString AcDbAttrib nv)
        ); case
       ); cond
       
      ); case
     ); cond
       
    ); foreach

    (foreach AcDbAttrib attributes
     (vlax-release-object AcDbAttrib) 
    )
   ); progn 
  ); if
  (vlax-release-object AcDbEntity)
 ); vlax-for

 (princ) 
); c:ASet

 

 

Message 6 of 47

mruPRQUJ
Advocate
Advocate

thank you so much, I am a little busy, but I will see if I can try it tomorrow, thanks a million!!!

0 Likes
Message 7 of 47

mruPRQUJ
Advocate
Advocate

Hello Mr. Moshe, I have saved the lisp as ASet.lsp. After I loaded it, type ASet, and then select objects, but nothing happened. Could you please provide some advice? Also, I wonder if it is possible to select items automatically, no selection is required. Many thanks.

0 Likes
Message 8 of 47

Moshe-A
Mentor
Mentor

@mruPRQUJ ,

 

i am not surprised it's does not work in fact if it would? it consider a miracle. 

do you have an idea why is that?

 

Moshe

 

0 Likes
Message 9 of 47

mruPRQUJ
Advocate
Advocate

no idea

 

0 Likes
Message 10 of 47

mruPRQUJ
Advocate
Advocate

could you please provide some advice for me? many thanks.

0 Likes
Message 11 of 47

Moshe-A
Mentor
Mentor

How about i do not have your title block?

 

 

0 Likes
Message 12 of 47

mruPRQUJ
Advocate
Advocate

sorry about it

 

0 Likes
Message 13 of 47

mruPRQUJ
Advocate
Advocate

please see attached two blocks, thanks a lot!

0 Likes
Message 14 of 47

mruPRQUJ
Advocate
Advocate

please let me know if you need any further information, thanks again

 

0 Likes
Message 15 of 47

Moshe-A
Mentor
Mentor

2. For the second scenario, the current value is 2A, 3A, 5A. The new value is 2, 3, 5 or 2B, 3B, 5B. There are two blocks. One block name is BCH-X-BORD-Dxxx, tag is REV_#.

Another block name is BCH-X-BORD-REVI, tag is R_NO.

 

how do i know when

2A, 3A, 5A, 10A turn to:

2, 3, 5, 10

or

2B, 3B, 5B, 10B

 

??

0 Likes
Message 16 of 47

Moshe-A
Mentor
Mentor

check this

0 Likes
Message 17 of 47

mruPRQUJ
Advocate
Advocate

sorry, please see the info below, 

2. For the second scenario, the current value is 2A, 3A, 5A. The new value is 2, 3, 5 or 2B, 3B, 5B. There are two blocks. One block name is BCH-X-BORD-Dxxx, tag is REV_#.

Another block name is BCH-X-BORD-REVI, tag is R_NO.      In one project, the new value is 2, 3, 5. In another project, the new value is 2B, 3B, 5B. I am not sure if they need to two different lisps. thanks a lot!

0 Likes
Message 18 of 47

mruPRQUJ
Advocate
Advocate

I will try it, many thanks.

0 Likes
Message 19 of 47

mruPRQUJ
Advocate
Advocate

Hi Mr. Moshe, It looks the same as before. I loaded it, type ASet, and then select objects, but nothing happened, many thanks.

0 Likes
Message 20 of 47

Moshe-A
Mentor
Mentor

@mruPRQUJ ,

 

attach a modification to the lisp

2A, 3A, 5A, 10A will now turn only to 2B, 3B, 5B, 10B

 


@mruPRQUJ wrote:

Hi Mr. Moshe, It looks the same as before. I loaded it, type ASet, and then select objects, but nothing happened, many thanks.


i hope you are selecting the right blocks, Works perfect on my AutoCAD. don't forget to change the REV_# & R_NO_D&E attributes from 1B to 1A.

 

Moshe

 

 

 

0 Likes