I'm looking for an AutoLISP routine that will update Mtext Attribute Blocks with a new string value.
There are 2 routines listed below for reference. The GetMtextAttrib routine gets a Mtext Attribute Block string value.
The PutEntNameAttrib routine only works for the traditional Text Attributes in Blocks.
This is the one that I need help on, to get it to work with Mtext Attributes in Blocks.
Both routines are in the attachment.
Thanks for your help.
Terry
Code:
;-------------------------------------------------------------------------------
; GetMtextAttrib - Get Block Mtext Attribute value
; Arguments: 2
; EntityName^ = Entity name
; AttrTag$ = Tag label of attribute
; Returns: Mtext Attribute value
;-------------------------------------------------------------------------------
(defun GetMtextAttrib (EntityName^ AttrTag$ / Text$)
(vl-some '(lambda (x) (and (= (vla-get-tagstring x) AttrTag$)(setq Text$ (vla-get-textstring x))))
(vlax-invoke (vlax-ename->vla-object EntityName^) 'getattributes)
);vl-some
(if (not Text$)
(setq Text$ "")
);if
Text$
);defun GetMtextAttrib
;-------------------------------------------------------------------------------
; PutEntNameAttrib - Put Entity name Attribute value
; Arguments: 3
; EntName^ = Entity name
; AttrTag$ = Tag label of attribute
; AttrVal$ = New value for attribute
; Returns: Changes attribute value
;-------------------------------------------------------------------------------
(defun PutEntNameAttrib (EntName^ AttrTag$ AttrVal$ / EntList@ EntTag$ EntType$ First)
(if (= (type EntName^) 'ENAME)
(progn
(setq EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
First t
);setq
(if (and (= EntType$ "INSERT") (assoc 66 EntList@))
(while (/= (cdr (assoc 0 EntList@)) "SEQEND")
(setq EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
EntTag$ (cdr (assoc 2 EntList@))
);setq
(if (= EntType$ "ATTRIB")
(if (and (= EntTag$ (strcase AttrTag$)) First)
(progn
(entmod (subst (cons 1 AttrVal$) (assoc 1 EntList@) EntList@))
(entupd EntName^)
(setq First nil)
);progn
);if
);if
(setq EntName^ (entnext EntName^))
);while
);if
);progn
);if
(princ)
);defun PutEntNameAttrib