Here's my attempt, as we could use this as well, but you will notice it only works with the first two line for some reason, not sure why:
cmwade77 , Thanks for sharing!
I publish your question in Chinese forum , and my boss give a answer.You can reference.
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=110871&page=1#pid646141
The bug modfiy by: edata @mjtd.com 2014-7-26
Thank you, also I found a slight bug in your code, any text after a blank line would not remain in the correct spot.
This is my corrected code, also this code will now copy all properties, as it simply makes a copy of the text and modifies it instead.
;Explode MText
;Explodes Mtext into single lines of mtext
;Written by: cmwade77 @ theswamp.org - July 2014
;Bug: Currenlty Only works on the first two lines of mtext
;Work Around: Repeat use until all lines are exploded
;Bug Fix by: edata @mjtd.com 2014-7-26
(defun c:explodemtext (/ SS Ent Object ObjectType Text NEWTEXT pt1 textlst txtobj LineCt Pt2 LSpace rot)
(defun Degrees->Radians (numberOfDegrees)
(* pi (/ numberOfDegrees 180.0))
)
(vl-load-com)
(while (= SS nil)
(princ "\rSelect MText to explode: ")
(setq Filter '((0 . "MTEXT"))
SS (ssget Filter)
)
)
((lambda (i / Ent)
(while (setq Ent (ssname SS (setq i (1+ i))))
(setq Object (vlax-ename->vla-object Ent)
ObjectType (vla-get-ObjectName Object)
)
(setq Text (vla-get-textstring Object)
pt1 (vla-get-InsertionPoint Object)
LSpace (vla-get-LineSpacingDistance Object)
pt1 (trans (vlax-safearray->list (vlax-variant-value pt1)) 0 1)
rot (vla-get-rotation Object)
)
(setq LineCt 0)
(setq textlst(parse12 Text "\\P"))
(while (setq NewText(car textlst))
(setq pt2 (trans (polar pt1 (- rot (Degrees->Radians 90.0)) (* LineCt LSPace)) 1 0)
pt2 (vlax-3d-point pt2)
LineCt (+ LineCt 1))
(setq txtobj (vla-copy Object))
(vla-put-textstring txtObj NewText)
(vla-put-InsertionPoint txtObj pt2)
(setq textlst(cdr textlst))
)
(vla-delete Object)
)
)
-1)
)
;;string delimiter
;;code By st788796
(defun parse12 (str delimiter / POST STRL STRLST)
(setq strl (strlen delimiter))
(while (vl-string-search delimiter str)
(setq post (vl-string-search delimiter str))
(setq strlst (append strlst (list (substr str 1 post))))
(setq str (substr str (+ post (1+ strl))))
)
(append strlst (list str));Code modified by cmwade77 to allow text after blanks lines to remain in place.
)
This should also account for all possible alignments and should work more reliably with versions older than 2009, as there were some properties that may not have been available.
NOTE: For those that have AutoCAD 2015, if the piece of mText was created in AutoCAD 2015, it will explode correctly with the normal explode command; however, if the text was created in 2014 or earlier, the mText will explode as CAB has described in his first post and one of the routines posted here is needed.
EDIT: Fixed problem with the code that was posted.
EDIT: Changed code to allow for rotated text, rotated UCS and to allow selecting multiple pieces of text.