;imp_exp
;import or export ASCII text files.

(defun import (/ xx x efpnt p1)
  (if (= just nil) (setq tsize 0.156 lspace 0.375 just "L"))
  (if (= efnam nil) (setq efnam ""))
  (setq efnam (GETFILed "Select ASCII Import File" "" "" 4))
  (setq efpnt (open efnam "r"))
  (if (= efnam nil)
    (princ (strcat "\n"(chr 34) efnam (chr 34) ": Can't open file"))
    (progn
      (initget 6)
      (setq X (getreal
        (strcat "\nEnter the text height <" (rtos tsize 2 3) ">: ")))
      (if (/= x nil) (setq tsize x))
      (initget 2)
      (setq X (getreal
        (strcat "\nEnter the line spacing <" (rtos lspace 2 3) ">: ")))
      (if (/= x nil) (setq lspace x))
      (graphscr)
      (initget 1 "C M R")
      (setq x (getpoint "\nStart point or Center/Middle/Right: "))
      (cond
        ((= (type x) 'List)
          (setq p1 x) (setq just "L")
        )
        ((= x "C")
          (setq just x)
          (initget 1)
          (setq p1 (getpoint "\nCenter point: "))
        )
        ((= x "M")
          (setq JUST X)
          (initget 1)
          (setq p1 (getpoint "\nMiddle point: "))
        )
        ((= x "R")
          (setq just x)
          (initget 1)
          (setq p1 (getpoint "\nEnd point: "))
        )
      )
      (setq crntl (read-line efpnt))
      (while crntl (If (= just "L")
        (command "text" p1 tsize 0 crntl)
        (command "text" just p1 tsize 0 crntl))
        (setq p1 (list (car P1) (- (cadr P1) lspace)))
        (setq crntl (read-line efpnt))
      )
      (close efpnt)
    )
  )
  (princ)
)

(defun export (/ a b c d e f g h i x oce)
  (setq oce (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq a (getstring "\nEnter the file name: "))
  (setq b (open a "r"))
  (if b
    (progn
      (princ "\nFile already exists.")
      (close b)
      (initget "Y N")
      (setq X (getkword "\nWould you like to over-write? <N> "))
      (if (= x "Y") (write-it))
    )
    (write-it)
  )
  (setvar "cmdecho" oce)
  (princ)
)

(defun write-it ()
  (setq c (open a "w"))
  (prompt "\nFile now open")
  (prompt "\nPick items in order to write to file")
  (setq d 0)
  (setq e (ssget))
  (setq f (sslength e))
  (repeat f
    (setq g (ssname e d))
    (setq h (entget g))
    (setq i (cdr (assoc 1 h)))
    (write-line i c)
    (setq d (+ 1 d))
  )
  (close c)
)

(defun c:haws-imp_exp ()
(haws-core-init 43)
  (setvar "cmdecho" 0)
  (initget 1 "Import Export")
  (setq ans (getkword "\nASCII text file <Import/Export>: "))
  (cond
    ((= ans "Import") (import))
    ((= ans "Export") (export))
  )
  (prin1)
)
