Hi all,
How can I pick text in a drawing to write to a file? I tried "txtout" (see code
below). It works fine except it won't select text that is a block.
; WRITE TEXT FROM A DRAWING TO AN ASCII FILE IN ORDER OF SELECTION
;;****************************************************************************
; TXTOUT.LSP V1.0 by Zoltan Toth
; ZOTO Technologies,
; 23 Greenhills Dve,
; Melton 3337.
; E-MAIL: zoltan.toth@ains.net.au
; WWW:
http://www.ains.net.au/zoto/;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This program will write text in a drawing to a nominated ASCII file.
; The lines will be written in order of selection and it is best to pick
; each line of text individually as selection by WINDOW, CROSSING etc.
; may result in lines being selected in an undesirable order. In the
; event that the nominated file already exists, the user has the option
; to overwrite or append to the existing file, or cancel the operation
; and start again. The ASCII file created by TXTOUT can then be ported
; to a text editor or word processor for editing and/or printing. It can
; also be read back into the drawing as MTEXT.
;;****************************************************************************
;define program name and localize variables
(defun C:TXTOUT (/ FN2 FD2 KWD2 SS2 CTR2 SSQTY2 OBJD2 OBTXT2)
(setq FN2 (getstring "\nText export file name: ")) ;get file name
(if (setq FD2 (open FN2 "r")) ;if file can be found
(progn
(close FD2) ;close file
(initget "Overwrite Append Cancel") ;initialize allowable keywords
(setq KWD2 (getkword "\nFile exists! Overwrite, Append or Cancel <O/a/c>: "))
)
)
(if (= "Cancel" KWD2) ;if user response was Cancel
(prompt "\nOperation cancelled at user's request.") ;prompt to confirm
(progn
(if (= "Append" KWD2) ;if user response was Append
(progn
(setq FD2 (open FN2 "a")) ;open file for appending
(prompt (strcat "\nFile \"" FN2 "\" now ready for appending."));and confirm
)
(progn
(setq FD2 (open FN2 "w")) ;else open file for (over)writing
(prompt (strcat "\nFile \"" FN2 "\" now open.")) ;and confirm
)
)
(prompt "\nPick text objects to export: ") ;prompt to select text
;select only TEXT & MTEXT
(setq SS2 (ssget '((-4 . "<OR")(0 . "TEXT")(0 . "MTEXT")(-4 . "OR>")))
CTR2 0 ;initialize counter CTR2 to zero
SSQTY2 (sslength SS2) ;find size of selection set
)
(repeat SSQTY2 ;repeat for each object
(setq OBJD2 (entget (ssname SS2 CTR2)) ;extract object data
OBTXT2 (cdr (assoc 1 OBJD2)) ;extract string value
CTR2 (1+ CTR2) ;increment counter
)
(write-line OBTXT2 FD2) ;write string to file
) ;end REPEAT
(close FD2) ;close file
(if (= "Append" KWD2) ;\inform user
(prompt (strcat "\n" (itoa SSQTY2) " lines appended to file.")); >of number
(prompt (strcat "\n" (itoa SSQTY2) " lines written to file.")) ;/ of lines
)
) ;end PROGN
) ;close "(if (= "Append"..."
(princ) ;exit quietly
)
Any ideas folks?
TIA
vinnyg