Jump to content

Recommended Posts

Posted (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:

Old.Format.thumb.png.fe5e80b9a31a3f05d29de9a6bd2ab6b7.png

 

This is the new format (this is what is desired):

New.Format.png.152b85fcfa34ecc57fc5f2ae61f1fe71.png

 

This is the old text in properties:

Old_Text.thumb.png.09589015924b6a62b70ea0f1988e2606.png

 

This is the new text in properties (this is what is desired):

New_Text.thumb.png.13b60381a569ec234fdf52996671324d.png

 

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 by GregGleason
Posted
44 minutes ago, GregGleason said:

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

You never define what 'new' is?

Posted

This is the "new" text in yellow (with a couple of carriage returns).

 

Replace_Code.thumb.png.b112d86f51c9a4626101797b51383d1d.png

 

Greg

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...