 |
|
Exchange Forum >
AutoLISP and Visual LISP
Text out to a file |
|
|
|
|
|
|
|
Omega |
 |
|
Join Date: |
|
08-20-2007 | |
Hi all,
Here’s a function that I’ve been working on that writes all text, mtext and attribute text to a text file. The filename is the drawing name with a txt extension. If the drawing has not been saved, it just prints the text to the text screen.
Code:
(defun c:TextOut (/ Elist Ename Enext Etype Fname Fopen SelectText Text Tlist)
(if (setq SelectText (ssget "x" (list '(0 . "TEXT"))))
(repeat (sslength SelectText)
(setq Ename (ssname SelectText 0))
(setq Elist (entget Ename))
(setq Text (cdr (assoc 1 Elist)))
(if (/= Text "")
(setq Tlist (append Tlist (list Text)))
)
(ssdel Ename SelectText)
)
)
(if (setq SelectText (ssget "x" (list '(0 . "MTEXT"))))
(repeat (sslength SelectText)
(setq Ename (ssname SelectText 0))
(setq Elist (entget Ename))
(setq Text (cdr (assoc 1 Elist)))
(if (/= Text "")
(setq Tlist (append Tlist (list Text)))
)
(ssdel Ename SelectText)
)
)
(if (setq SelectText (ssget "x" (list '(-4 . "<AND")'(0 . "INSERT")'(66 . 1)'(-4 . "AND>"))))
(repeat (sslength SelectText)
(setq Ename (ssname SelectText 0))
(setq Elist (entget Ename))
(setq Enext Ename)
(while (/= (cdr (assoc 0 Elist)) "SEQEND")
(setq Elist (entget Enext))
(setq Etype (cdr (assoc 0 Elist)))
(setq Text (cdr (assoc 1 Elist)))
(if (and (= Etype "ATTRIB")(/= Text ""))
(setq Tlist (append Tlist (list Text)))
)
(setq Enext (entnext Enext))
)
(ssdel Ename SelectText)
)
)
(if Tlist
(progn
(foreach Text Tlist ;Optional foreach command princ
(princ (strcat "\n" Text))
)
(if (/= (getvar "DWGTITLED") 0) ;Drawing has been saved
(progn
(setq Fname (strcat (getvar "DWGPREFIX")(getvar "DWGNAME")))
(setq Fname (strcat (substr Fname 1 (- (strlen Fname) 3)) "txt"))
(setq Fopen (open Fname "w"))
(foreach Text Tlist
(write-line Text Fopen)
)
(close Fopen)
)
)
)
)
(princ)
)
| |
|
|
|
J Moreno |
 |
|
Join Date: |
|
07-30-2007 | |
I tested your program and it works fine. What do you use it for? Is it like a text database file?
| |
|
|
|
Omega |
 |
|
Join Date: |
|
08-20-2007 | |
Well this is just my first attempt at this. I thought it might be useful for searching for project information in text files versus drawing files. I may just limit it to just include attribute title block information.
| |
|
|
|
|
|