To export contents of one or multiple text (mtext) objects to a file as follows:
1) Select text and mtext objects you want to extract text
2 )Start command text2file
2) If asked for a first time it will ask for destination folder and name of text file basic string (file, textbox)
3) Contents of that text entities will be written to "basicstring1.txt)
4) At the end it opens that file in notepad
If you select unwanted object it won't mater, and it will save you from beeps.


(defun c:text2file ( / LM:browseforfolder inittextout f file e i ent ss ty text listout)
; Extract text or mtext object to file
; hak_vz 30.11.2019
;
(defun *error* ()
(close file)
(princ)
)
(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
;; Browse for Folder - Lee Mac
;; Displays a dialog prompting the user to select a folder.
;; msg - [str] message to display at top of dialog
;; dir - [str] [optional] root directory (or nil)
;; bit - [int] bit-coded flag specifying dialog display settings
;; Returns: [str] Selected folder filepath, else nil.
(setq err
(vl-catch-all-apply
(function
(lambda ( / app hwd )
(if (setq app (vlax-get-acad-object)
shl (vla-getinterfaceobject app "shell.application")
hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
)
(setq slf (vlax-get-property fld 'self)
pth (vlax-get-property slf 'path)
pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
)
)
)
)
)
)
(if slf (vlax-release-object slf))
(if fld (vlax-release-object fld))
(if shl (vlax-release-object shl))
(if (vl-catch-all-error-p err)
(prompt (vl-catch-all-error-message err))
pth
)
)
(defun inittextout () ;variables are globals
(setq folderout (LM:browseforfolder "Select a folder" nil 0))
(setq fileoutname (getstring "\nName of output files base >"))
(setq filecounter 0)
(princ)
)
(if (not folderout) (inittextout))
(setq filecounter (1+ filecounter))
(setq f (strcat folderout "/" fileoutname (itoa filecounter) ".txt"))
(setq file (open f "w"))
(setq ss (cadr (ssgetfirst)) i 0)
(while (< i (sslength ss))
(setq e (ssname ss i) ent (entget e))
(setq ty (strcase(cdr (assoc 0 ent)) T))
(setq text (cdr (assoc 1 ent)))
(if (= ty "mtext")
(while (wcmatch text "*\\P*") (setq text (vl-string-subst "\n" "\\P" text)))
)
(setq listout (cons text listout))
(setq i (1+ i))
)
(foreach e listout
(write-line e file)
)
(close file)
(princ (strcat "\nData is writen to " f))
(startapp "notepad" f)
(princ)
)I hope it works for you. If it does, set this post as a final solution.
Miljenko Hatlak

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.