I have been searching for a routine similar to this post about how to get a block attribute mtext value and also how to change it's value.
Please review the attached LISP routines GetEntNameAttrib.lsp and PutEntNameAttrib.lsp.
Both of these only work for the traditional text attributes, but not for mtext attributes for blocks.
I would appreciate your help or leads to where I can find out how to modify my routines to work with mtext attributes.
Thanks
Code:
;-------------------------------------------------------------------------------
; GetEntNameAttrib - Get Entity name Attribute value
; Arguments: 2
; EntityName^ = Entity name
; AttrTag$ = Tag label of attribute
; Returns: Attribute value
;-------------------------------------------------------------------------------
(defun GetEntNameAttrib (EntityName^ AttrTag$ / AttrVal$ EntAttr$ EntList@ EntName^ EntTag$ EntType$)
(if (= (type EntityName^) 'ENAME)
(progn
(setq EntName^ EntityName^
EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
);setq
(if (and (= EntType$ "INSERT") (assoc 66 EntList@))
(while (/= (cdr (assoc 0 EntList@)) "SEQEND")
(setq EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
EntAttr$ (cdr (assoc 1 EntList@))
EntTag$ (cdr (assoc 2 EntList@))
);setq
(if (= EntType$ "ATTRIB")
(if (= EntTag$ (strcase AttrTag$))
(setq AttrVal$ EntAttr$)
);if
);if
(setq EntName^ (entnext EntName^))
);while
);if
);progn
);if
AttrVal$
);defun GetEntNameAttrib
;-------------------------------------------------------------------------------
; PutEntNameAttrib - Put Entity name Attribute value
; Arguments: 3
; EntityName^ = Entity name
; AttrTag$ = Tag label of attribute
; AttrVal$ = New value for attribute
; Returns: Changes attribute value
;-------------------------------------------------------------------------------
(defun PutEntNameAttrib (EntityName^ AttrTag$ AttrVal$ / EntList@ EntName^ EntTag$ EntType$ First)
(if (= (type EntityName^) 'ENAME)
(progn
(setq EntName^ EntityName^
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
;-------------------------------------------------------------------------------