Jump to content

MText Formatting Problem - Adding a New Line


Recommended Posts

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

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)))
  (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))

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?



Edited by GregGleason
Link to comment
Share on other sites

44 minutes ago, GregGleason said:

(vla-put-textstring o (string_subst (vla-get-textstring o) old new))

You never define what 'new' is?

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...