Replacing the text inside an MText, there are 2 basic ways. Assume you have the text you want stored in a lisp variable STR and have the MText selected and its ename stored in a lisp variable en:
1. Through entmod.1a. That could cause problems with annotatively scaled text. For that reason I would go with this rather:Code:(setq ed (entget en)) ;Get the DXF data list (setq ed (subst (cons 1 str) (assoc 1 ed) ed)) ;Modify the DXF list (entmod ed) ;Modify the entity2. The vla methods (also doesn't give annotative problems)Code:(entmod (list (cons -1 en) (cons 1 str)))To append to it, you'll need to obtain the existing value first:Code:(vl-load-com) ;Ensure VLisp extensions are loaded, only need to do this once per DWG. (setq eo (vlax-ename->vla-object en)) ;Get the ActiveX object of the entity (vla-put-TextString eo str) ;Change the text inside the MText
1. Again watch out for annotative scaling1a. This becomes a bit forcedCode:(setq ed (entget en)) ;Get the DXF data list (setq ed (subst (cons 1 (strcat (cdr (assoc 1 ed)) str)) (assoc 1 ed) ed)) ;Modify the DXF list (entmod ed) ;Modify the entity2. IMO the easiest wayCode:(setq ed (entget en)) ;Get the DXF data list (entmod (list (cons -1 en) (cons 1 (strcat (cdr (assoc 1 ed)) str))))Code:(setq eo (vlax-ename->vla-object en)) ;Get the ActiveX object of the entity (vla-put-TextString eo (strcat (vla-get-TextString eo) str)) ;Change the text inside the MText



Reply With Quote


Bookmarks