AutoLISP: Combine Text

Link to AutoCAD Tips

Here is a useful way to combine two text objects. You can even combine DTEXT objects with MTEXT and vice-versa…

Here’s how:

  • CT <enter> to start Combine Text
  • Select the first text object. (this will be the base text object that the next text object will be added to)
  • Select the second text object.

~enjoy

(princ "\CT.LSP (Combine Text) - Matt Pittman\n")
(defun C:ct (/ );1strg text1 t1 spc 2strg text2 t2 comb)
(setq 1strg (entget (car (entsel "\nPick 1st Text.. "))))
(setq text1 (assoc 1 1strg))
(setq t1 (cdr (assoc 1 1strg)))
(setq spc " ")
(setq 2string (entsel "\nPick 2nd Text.. "))
(setq 2s (car 2string))
(setq 2strg (entget (car 2string)))
(setq text2 (assoc 1 2strg))
(setq t2 (cdr (assoc 1 2strg)))
(entdel 2s)
(setq comb (strcat t1 spc t2))
(setq comb (cons 1 comb))
(setq 1strg (subst comb text1 1strg))
(entmod 1strg)
(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, AutoLISP: Modify, AutoLISP: Text, Modifying, Text. Bookmark the permalink.

One Response to AutoLISP: Combine Text

  1. Alex says:

    great lisp – can it be enhanced to combine more than 2 items of Dtext on a single line?

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