AutoLISP: Join MTEXT

I recently found this little routine and I am sure going to be using it. Heck, I could have used it for a while now.

It is simple. It joins MTEXT objects into a single MTEXT object.

Here’s how:

  • JMTX <enter> to start
  • Select the MTEXT objects to be joined. (Note: the order in which you select the MTEXT objects will determine the order the final MTEXT object.)
  • <enter> to finish
;; by Joe Burke at Autodesk Forums

;; Join mtext demo.

;; The order of selection determines the result.

;; The first mtext object selected is modified and

;; others are deleted.

(defun c:jmtx ( / e obj lst str)

(vl-load-com)

(while

(and

(setq e (car (entsel "\nSelect mtext: ")))

(setq obj (vlax-ename->vla-object e))

(equal "AcDbMText" (vlax-get obj 'ObjectName))

)

(setq lst (cons obj lst))

)

(setq obj (last lst))

(setq str (vlax-get obj 'TextString))

(foreach x (cdr (reverse lst))

(setq str (strcat str "\\P" (vlax-get x 'TextString)))

(vla-delete x)

)

(vlax-put obj 'TextString str)

(princ)

)


Advertisements

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, Modifying, Text. Bookmark the permalink.

4 Responses to AutoLISP: Join MTEXT

  1. josh642 says:

    its been a few years since ive used customized commands. is the file extension for the code above “.lsp”? also, you load it with “@appload”, correct? thank you!

  2. Will says:

    cheers for this script

  3. Greg says:

    This works great! I was not having the repetitive edit, select all, copy, escape, edit, paste, escape routine.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s