Legal
notices:
- This sample program is intended as a demonstration only.
- The program is available on an 'as-is' basis with no warranties,
either expressed or implied, of any kind.
- You may use the program only at your own risk.
- No license or rights to the program are either given or forfeited.
Everything that follows is direct and unaltered output from the LISP
Generator.
; This program was created on December 8 2006 using the LISP Generator.
; Define the function (the program).
(defun c:TXT2FILE ( / FL1 SS1 OBJ I HNDL TXTSTR OLDCE OLDERR OLDTE)
; Save the current value of cmdecho then redefine it.
(setq OLDCE (getvar "cmdecho"))
(setvar "cmdecho" 1)
; Save the current value of texteval then set it to 1
(setq OLDTE (getvar "texteval"))
(setvar "texteval" 1)
; Save the current value of the error handling subroutine then
redefine it.
(setq OLDERR *error*)
(defun *error* (errmes)
(princ (strcat "\nExecution of TXT2FILE halted by
the following error: " ERRMES))
(setvar "cmdecho" OLDCE)
(setq *error* OLDERR)
(prin1)
)
;(setq *error* nil)
; NOTE: to turn error handling off, erase the semicolon in the
line above. 
; GET a FILE from the user and store it in FN1.
(setq FN1 (getfiled "Output file" "textout.txt" "" 5))
; OPEN file FN1 for overwriting as FL1.
(setq FL1 (open FN1 "w"))
; QUERY the drawing and store the resulting selection set in
SS1.
(setq SS1 (SSGET "X" (QUOTE ((0 . "TEXT")))))
; BEGIN LOOP loop1.
; LOOP by STEPPING THROUGH the OBJECTS of SELECTION-SET SS1,
reading them into OBJ. 
(setq I -1)
(while (setq OBJ (ssname SS1 (setq I (1+ I))))
; EXTRACT the Handle from the entity OBJ and store
it in HNDL.
(setq HNDL (cdr (assoc 5 (entget OBJ))))
; EXTRACT the Text string from the entity OBJ and
store it in TXTSTR.
(setq TXTSTR (cdr (assoc 1 (entget OBJ))))
; WRITE to file FL1.
(princ HNDL FL1)
(princ "\n" FL1)
(princ TXTSTR FL1)
(princ "\n" FL1)
) ; END LOOP loop1.
; CLOSE file FL1.
(close FL1)
; Reset "cmdecho" to previous value. 
(setvar "cmdecho" OLDCE)
; Reset "texteval" to previous value.
(setvar "texteval" OLDTE)
; Reset *error* to previous definition.
(setq *error* OLDERR)
; Exit quietly (no return value.)
(prin1)
)