Jump to content

Attribute value Update globally without changing the existing


thbaiju
 Share

Recommended Posts

Hi all,

could you please give me a solution to update block attribute value in multiple layouts with out changing the existing values.

eg:

Tag

DT3

Value

"part-01"

 

I need to edit the value as "MEP Part-01"

The multiple layout have different numbers.

So I need to add "MEP" to all layouts.

 

Thanks for reading

Link to comment
Share on other sites

The following macro should work, it will change all values of DT3 to add MEP-, a macro wont accept a space in the string hence the - at the end

^C^C-attedit;n;n;;DT3;;;MEP-;

But please use this on a copy of the file first to check the results

Link to comment
Share on other sites

@tharwat

 

Block name is "Title-A1-Text" and i need to change according to the tag "DT3"

multiple layout have different values eg: layout-1 have part-01, layout-2 have part-2 etc...

I need to add "MEP" before part-01, part-02 etc...with out changing the part numbers in each layout

Link to comment
Share on other sites

@tharwat

 

Block name is "Title-A1-Text" and i need to change according to the tag "DT3"

multiple layout have different values eg: layout-1 have part-01, layout-2 have part-2 etc...

I need to add "MEP" before part-01, part-02 etc...with out changing the part numbers in each layout

 

Thanks for your reply .

 

Did the code that posted by pBe helped you with it ?

Otherwise , if you can upload a sample drawing , it would be great to test my code on it :)

Link to comment
Share on other sites

Anyway try this UNTESTED routine and let me know .

 

(defun c:Test (/ tag ss lock)
 ;; Tharwat 22. Oct. 2013    ;;
 (or acdoc
     (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
 )
 (vlax-for x (vla-get-layers acdoc)
   (if (eq :vlax-true (vla-get-lock x))
     (vla-put-lock (car (setq lock (cons x lock))) :vlax-false)
   )
 )


 (if (setq tag "DT3"
           ss  (ssget "_X"
                      '((0 . "INSERT") (66 . 1) (2 . "Title-A1-Text"))
               )
     )
   (progn
     (vla-StartUndoMark acdoc)
     ((lambda (x / sn e)
        (while (setq sn (ssname ss (setq x (1+ x))))
          (while
            (and (setq sn (entnext sn))
                 (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND")
            )
             (if (and (eq (cdr (assoc 0 e)) "ATTRIB")
                      (eq (strcase (cdr (assoc 2 e))) tag)
                 )
               (entmod (subst (cons 1 (strcat "MEP " (cdr (assoc 1 e))))
                              (assoc 1 e)
                              e
                       )
               )
             )
          )
        )
      )
       -1
     )
     (vla-EndUndoMark acdoc)
   )
 )
 (foreach layer lock (vla-put-lock layer :vlax-true))
 (vla-regen acdoc AcAllViewports)
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

Block name is "Title-A1-Text" and i need to change according to the tag "DT3"

multiple layout have different values eg: layout-1 have part-01, layout-2 have part-2 etc...

I need to add "MEP" before part-01, part-02 etc...with out changing the part numbers in each layout

 

To accommodate the conditions you posted.:

(defun c:c2 (/ ss i e tag str_ str)
   (setq tag  "DT3"
  str_ "*PART*"
   )
   (if	(setq ss (ssget "_X" '((0 . "INSERT") (66 . 1)(2 . "`*U*,Title_A1_Text")(410 . "~Model"))))
     (repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (Setq i (1- i)))))
(if (and (Eq (Strcase (vla-get-effectivename e)) "TITLE_A1_TEXT")
         (vlax-write-enabled-p e))
  (vl-some
    '(lambda (x)
       (if
	 (and
	   (eq (vla-get-tagstring x) tag)
	   (wcmatch (strcase (setq str (vla-get-textstring x))) str_)
	   (not (wcmatch str "[MmEePp]*"))
	 )
;;; in case layer "0" is also locked considering	;;;
;;; most blocks are created at layer "0"		;;;
	  (vl-catch-all-error-p
	    (vl-catch-all-apply
	      'vla-put-textstring
	      (list x (strcat "MEP " str))
	    )
	  )
;;;							;;;
       )
     )
    (vlax-invoke e 'Getattributes)
  )
)
     )
   )
   (princ)
 )

Edited by pBe
To work OP's drawing sample
Link to comment
Share on other sites

Hi all,

i am attaching the drawing here, hopes it easy...

 

You did give the name of the Attributed Block wrongly in your post No# 5 .

 

So change the name of the Block in my code as shown bellow :

 

(setq tag "DT3" ss  (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "[color=red]Title-A1-Text[/color]")) ))

Run the code and let me know .

Link to comment
Share on other sites

My 2 cents, completely borrowed from Patrick's code:


(defun C:TBP (/ adoc alayouts match tag)
   (setq 
tag  "DT3"
  match "(PART *"

)
 (setq adoc 
(vla-get-activedocument(vlax-get-acad-object))
alayouts 
(vla-get-layouts adoc))
 (vlax-for alayout alayouts  

     (vlax-for obj (vla-get-block 
alayout)
(if (and (eq "AcDbBlockReference"(vla-get-objectname 
obj))
  (eq (strcase (vla-get-effectivename obj)) 
"TITLE_A1_TEXT")

(vlax-write-enabled-p obj))
  (vl-some

'(lambda (x)
       (if

(and
    (eq (vla-get-tagstring x) 
tag)
    (wcmatch (strcase (setq str (vla-get-textstring 
x))) match)
  )

(vl-catch-all-error-p

(vl-catch-all-apply

'vla-put-textstring
       (list x 
(strcat "MEP " str))
     )

)

)
     )
    (vlax-invoke 
obj 'getattributes)

)
)
     )

)
   (princ)
 )

Thanks, PBe :)

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

 Share

×
×
  • Create New...