thbaiju Posted October 22, 2013 Posted October 22, 2013 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 Quote
Tharwat Posted October 22, 2013 Posted October 22, 2013 Welcome to CadTutor - What is the name of Attributed Block ? - Do you want to change the value according according to Part-01 or according to Tag name ? Tharwat Quote
steven-g Posted October 22, 2013 Posted October 22, 2013 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 Quote
pBe Posted October 22, 2013 Posted October 22, 2013 (edited) quickee... ....removed... Edited October 23, 2013 by pBe Quote
thbaiju Posted October 22, 2013 Author Posted October 22, 2013 @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 Quote
Tharwat Posted October 22, 2013 Posted October 22, 2013 @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 Quote
Tharwat Posted October 22, 2013 Posted October 22, 2013 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) Quote
pBe Posted October 22, 2013 Posted October 22, 2013 (edited) 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 October 23, 2013 by pBe To work OP's drawing sample Quote
thbaiju Posted October 23, 2013 Author Posted October 23, 2013 Hi all, i am attaching the drawing here, hopes it easy... Attri-Test.dwg Quote
pBe Posted October 23, 2013 Posted October 23, 2013 Updated the code at post #8 to meet your conditions HTH Quote
Tharwat Posted October 23, 2013 Posted October 23, 2013 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 . Quote
fixo Posted October 23, 2013 Posted October 23, 2013 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 Quote
Recommended Posts
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.