home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
felixcad
/
fcaddata.z
/
TEXTOUT.LSP
< prev
next >
Wrap
Lisp/Scheme
|
1996-09-23
|
4KB
|
115 lines
;;; TEXTOUT.LSP
;;; ======================================================================
;;; Text Utilility TEXTOUT. Write drawing text lines to text file.
;;; Provided by Felix Computer Aided Technologies GmbH 1996 as Lisp Sample
;;; ======================================================================
;;; DESCRIPTION:
;;; The utility TEXTOUT allows to write text selected in the drawing to
;;; an ASCII file.
;;; The routine checks, if the specified file already exists. In the case
;;; that it exists, the selected text may be appended to the file, if
;;; desired.
;;; ======================================================================
;;; SAMPLE FOR:
;;; alert, gefiled, open, close
;;; ssget, sslength, ssname, entget, ...
;;; ======================================================================
(defun C:TEXTOUT ( / *ERROR* write_mode ss n e pf fn msg1 msg2 t_lines)
(if (> (getvar "ACTDB") -1) (progn
;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(defun *ERROR* (msg)
(setq *ERROR* nil)
(princ)
)
;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(setq fn (GETFILED "Export Text" "" "txt" 4))
(if fn (progn
(if (setq pf (OPEN fn "R"))
(progn
(CLOSE pf) ;;; close file if open
(setq msg1 (strcat
"File already exists: "
fn
"\n\nReplace file?"
))
(setq msg2 (strcat
"File already exists: "
fn
"\n\nAppend lines to file?"
))
(if (ALERT msg1 "Export Text" "QUESTION") ;;; returns T or nil
(setq write_mode "W")
(if (ALERT msg2 "Export Text" "QUESTION")
(setq write_mode "A")
(progn
(setq write_mode nil)
(ALERT
"Text Export canceled.\nFile left unchanged!"
"Export Text"
"INFORMATION"
)
)
)
)
)
;;; ### ELSE: Open filename in write mode - to check if filename is valid
(if (setq pf (open fn "W"))
(progn
(close pf)
(setq write_mode "W")
)
(progn
(ALERT
(strcat
"Invalid filename or path specification: \n"
fn
)
"Export Text"
"EXCLAMATION"
)
(setq write_mode nil)
)
)
)
;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(if write_mode (progn
(princ "Select text lines... ")
(if (setq ss (ssget))
(progn
(if (setq pf (open fn write_mode)) (progn
(setq n 0 t_lines 0)
(repeat (sslength ss)
(setq e (entget (ssname ss n)))
(if (member (cdr (assoc 0 e)) '("TEXT" "ATTRIB"))
(progn
(write-line (cdr (assoc 1 e)) pf)
(setq t_lines (1+ t_lines))
)
)
(setq n (1+ n))
)
(close pf)
(princ (strcat
(itoa t_lines) " lines written to file: "
fn "!"
))
)) ; if
) ; progn
(princ "No text has been selected!")
) ; if
)) ; if progn
)) ; if progn
(setq *ERROR* nil) ;;; Restore System Error Handling
)) ;; ACTDB
(princ)
)
;;; =========================================================================
(princ "Command TEXTOUT loaded.")
(setfunhelp "C:TEXTOUT" "TEXTOUT" "fcad")
(terpri)
(princ)