GregGleason Posted April 24, 2019 Posted April 24, 2019 (edited) I want to add text to an existing MTEXT, but the utility I have used doesn't support what I am trying to do. I can select it fine, but it doesn't come out right. This is the old format: This is the new format (this is what is desired): This is the old text in properties: This is the new text in properties (this is what is desired): I tried to use this code to call a MRWA.lsp (but the format doesn't work right): (setq mylisp "MRWA.lsp") ; Set the lisp routine name (setq mypatlsp (strcat mypath mylisp)) ; Set the path/file of the lisp routine name (load mypatlsp) ; Load the lisp routine (replace "INSPECTION AND WELDING." "INSPECTION AND WELDING. NORTH IS BASED ON PLANT NOTRTH PER DWG 123-KD-401.") ; Replace MTEXT string: old/new Using this lisp (MRWA.lsp): (defun replace (old new / string_subst dxf idx o ss) (defun string_subst (str old new / idx) (setq idx 0) (while (setq idx (vl-string-search old str idx)) (setq str (vl-string-subst new old str idx)) (setq idx (+ idx (strlen new))) ) str ) (if (setq ss (ssget "_X" (list '(0 . "MTEXT") (cons 410 (getvar 'ctab))))) (repeat (setq idx (sslength ss)) (setq o (vlax-ename->vla-object (ssname ss (setq idx (1- idx))))) (if (vl-string-search old (vla-get-textstring o)) (vla-put-textstring o (string_subst (vla-get-textstring o) old new)) ) ) ) (princ) ) Am I just a few characters off to get this to work right? Or do I need to take another path to make this work? Greg Edited April 24, 2019 by GregGleason Quote
ronjonp Posted April 24, 2019 Posted April 24, 2019 44 minutes ago, GregGleason said: (vla-put-textstring o (string_subst (vla-get-textstring o) old new)) You never define what 'new' is? Quote
GregGleason Posted April 24, 2019 Author Posted April 24, 2019 This is the "new" text in yellow (with a couple of carriage returns). Greg 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.