From: blu@cellar.org (Dan Reed)
Newsgroups: alt.cad.autocad
Subject: Re: Text from a drawing
Date: 8 Jan 93 21:33:50 GMT
Organization: The Cellar BBS and public access system

dlb@controls.ccd.harris.com (Doug Bennett) writes:

> rebeccae@KINGTUT.COLORADO.EDU (Rebecca Esparza) writes:
> : I'm trying to save myself some work.  Does anyone know
> : if there is a way to export text from a drawing to an
> : ascii text file?
> : 
> : Thanks,
> : Rebecca Esparza
> : rebeccae@kingtut.colorado.edu


Yes, try this..
---Cut ME HERE!---

 
(defun MODES (a)
   (setq MLST '())
   (repeat (length a)
      (setq MLST (append MLST (list (list (car a) (getvar (car a))))))
      (setq a (cdr a)))
)
 
(defun MODER ()
   (repeat (length MLST)
      (setvar (caar MLST) (cadar MLST))
      (setq MLST (cdr MLST))
   )
)
 
 
(defun atxterr (st)                  
                                     
  (if (/= st "Function cancelled")
      (princ (strcat "\nError: " st))
  )
  (moder)                             ; Restore modified modes
  (if (= (type rtfile) 'FILE) (close rtfile))
  (setq rtfile nil)
  (setq *error* olderr)               ; Restore old *error* handler
  (princ)
)
 
 
   ;Function for inserting text a recalculation of insertion
   ;point.
 
   (defun 1LTXT ()
      (if (member '1 opt) (setq s (strcat "%%u" s "%%u")))
      (if (member '2 opt) (setq s (strcat "%%o" s "%%o")))
      (if (member '4 opt) (setq s (strcase s)))
      (if (member '8 opt) (setq s (strcase s T)))
      (if (and (= lc (1+ nl)) (/= nl 0))
          (progn
           (setq lc 1)
           (setq pt (polar pt1 ang cd))
           (setq pt1 pt)
          )
      )
      (cond ((and (= j "L") h)
             (command "TEXT" pt h (rtd ang) s)
            )
            ((and (/= j "L") h)
             (command "TEXT" j pt h (rtd ang) s)
            )
            ((and (= j "L") (null h))
             (command "TEXT" pt (rtd ang) s)
            )
            ((and (/= j "L") (null h))
             (command "TEXT" j pt (rtd ang) s)
            )
      )
      (if (/= d "Auto")
          (if (= (cdr (assoc 70 ts)) 4)
              (setq pt (polar pt (+ (dtr 90) ang) d))
              (setq pt (polar pt (+ (dtr 270) ang) d))
          )
      )
      (setq c (1+ c))
      (if (= c n)
          (setq eof T)
      )
   )
 
   ;Degrees to radians conversion
   (defun DTR (y)
    (* pi (/ y 180.0))
   )
   ;Radians to degrees conversion
   (defun RTD (Y)
    (* 180.0 (/ y pi))
   )
 
;********************** MAIN PROGRAM ***************************
 
 
(defun C:ASCTEXT (/ olderr ang c cd d eof rtfile rf h
                    j l1 opt pt pt1 ts n nl lc s ul)
 
  ; a$$ holds default ANGLE
  ; f$$ holds default fILE
 
  (setq olderr  *error*
        *error* atxterr)
  (modes '("BLIPMODE" "CMDECHO" "HIGHLIGHT"))
 
  (while (null rtfile)
         ;Prompt for file to be inserted
         (if (null f$$)
             (progn
              (initget 1)
              (prompt "\nFile to read (including extension): ")
             )
             (progn
              (prompt "\nFile to read (including extension)/<")
              (princ (strcat f$$ ">: "))
             )
         )
         (setq rf (getstring))
         (if (and (= rf "") (/= nil f$$))
             (setq rf f$$)
         )
         (setq rtfile (open rf "r"))
         (if rtfile
             (setq f$$ rf)
             (prompt "\nFile not found. ")
         )
  )
 
  ;Prompt for start point or justification
  (initget 1  "Center Middle Right")
  (setq pt (getpoint
             "\nStart point or Center/Middle/Right: "
           )
  )
  (if (/= (type pt) 'LIST)
      (setq j (substr pt 1 1))
      (setq j "L")
  )
 
 
  ;Prompt for an insertion point
  (if (/= (type pt) 'LIST)
      (progn
       (initget 1)
       (setq pt (getpoint (strcat "\n" pt " point: ")))
      )
  )
  (setq pt1 pt)  ; First insertion point
 
  ;Prompt for a text height
  (setq ts (tblsearch "STYLE" (getvar "TEXTSTYLE"))
        h nil
  )
  (if (= (cdr (assoc 40 ts)) 0.0)
      (progn
        (initget 6)
        (setq h (getdist pt (strcat "\nHeight <"
                                    (rtos (getvar "TEXTSIZE"))
                                    ">: "
                            )
                )
        )
        (if (null h) (setq h (getvar "TEXTSIZE")))
      )
  )
 
  ;Prompt for rotation angle of text
  (if (null a$$)
      (progn
       (if (= (cdr (assoc 70 ts)) 4)  ; Vertical style text
           (progn
            (setq a$$ 270)
            (prompt "\nRotation angle <270>: ")
           )
           (progn
            (setq a$$ 0)
            (prompt "\nRotation angle <0>: ")
           )
       )
      )
      (progn
       (prompt "\nRotation angle <")
       (princ (strcat (angtos a$$) ">: "))
      )
  )
  (setq ang (getangle pt))
  (if (null ang) (setq ang a$$))
  (setq a$$ ang)
 
  (setq d "Auto" l1 1 n "All" opt nil lc 0 nl 0 c 0)
 
  (initget "Yes No")
  (if (= "Yes"  (getkword "\nChange text options? <N>: "))
     (progn
 
       ;Prompt for distance between lines.
       (initget "Auto")
       (setq d (getdist pt "\nDistance between lines/<Auto>: "))
       (if (= d nil) (setq d "Auto"))
 
       ;Prompt for first line to read.
       (initget (+ 2 4))
       (setq l1 (getint "\nFirst line to read/<1>: "))
       (if (null l1) (setq l1 1))
 
       ;Prompt for number of following lines.
       (initget (+ 2 4) "All")
       (setq n (getint "\nNumber of lines to read/<All>: "))
       (if (= n "All") (setq n nil))
 
       (initget "Yes No")
       (if (= "Yes" (getkword "\nUnderscore each line? <N>: "))
           (setq opt (append opt '(1)))
       )
       (initget "Yes No")
       (if (= "Yes" (getkword "\nOverscore each line? <N>: "))
           (setq opt (append opt '(2)))
       )
 
       ; Option for global redefinition of text case.
       (initget "Upper Lower No")
       (prompt "\nChange text case? ")
       (setq ul (getkword "  Upper/Lower/<N>: "))
       (cond ((= ul "Upper") (setq opt (append opt '(4))))
             ((= ul "Lower") (setq opt (append opt '(8))))
       )
 
       ; Option for setting up columns.
       (initget "Yes No")
       (if (= "Yes" (getkword "\nSet up columns? <N>: "))
           (progn
            (setq opt (append opt '(16)))
            (initget (+ 1 2))
            (setq cd (getdist pt "\nDistance between columns: "))
            (initget (+ 1 2 4))
            (setq nl (getint "\nNumber of lines per column: "))
           )
       )
 
     )
  )
  (setvar "BLIPMODE" 0)
  (setvar "HIGHLIGHT" 0)
  (setvar "CMDECHO" 0)
 
  (setq eof nil)
  (setq s (repeat l1 (read-line rtfile)))
 
  (setq lc (1+ lc))
  (1ltxt)
  (while (null eof)
    (if (= d "Auto")
        (progn
         (setq s (read-line rtfile))
         (setq lc (1+ lc))
         (if s
           (progn
            (if (= lc (1+ nl))
                (1ltxt)
                (progn
                 (if (member '1 opt) (setq s (strcat "%%u" s "%%u")))
                 (if (member '2 opt) (setq s (strcat "%%o" s "%%o")))
                 (if (member '4 opt) (setq s (strcase s)))
                 (if (member '8 opt) (setq s (strcase s T)))
                 (command "TEXT" "" s)
                 (setq c (1+ c))
                 (if (= c n) (setq eof T))
                )
            )
           )
           (setq eof T)
         )
        )
        (progn
         (setq s (read-line rtfile))
         (setq lc (1+ lc))
         (if s (1ltxt) (setq eof T))
        )
    )
  )
  (close rtfile)                    
  (setq rtfile nil)
  (moder)                             ; Restore modified modes
  (setq *error* olderr)               ; Restore old *error* handler
  (princ)
)

     Dan Reed - blu@cellar.org - AutoCAD Geek -Industrial Music Lover
      68'Cougar, 89'VW Golf, 74'Honda Cb360, 89'Rollerblade Zetras'
  "Anyone can get a gun Otis. You can make a phone call and get a gun."