Tblin AutoLisp Modes
![](https://victoromark.com/wp-content/uploads/markus-spiske-hvSr_CVecVI-unsplash-1024x683.jpg)
(defun c:tblin (/)
;Initialize counters.
(setq Row 0)
(setq Col 0)
;Change these variables to adjust row and columns.
(setq OffCol 2)
(setq OffRow 0.2)
(setq ColMax 9)
(setq eof 0)
(setq Filename (FileToRead))
(setq FileHandler (open Filename “r”))
(while (= eof 0)
(progn
(while (< Col (* OffCol ColMax))
(progn
(setq TextIn (read-line FileHandler))
(if (= TextIn “~”)
(setq eof 1)
;Else
(progn
(setq Col (+ Col OffCol))
(command “TEXT” (list Col Row 0.0) “0.08” “0” TextIn)
);End progn
);End if
);End progn
);wend
(setq Row (- Row OffRow))
(setq Col 0)
);End progn
);Wend
(close FileHandler)
(princ)
)
(defun FileToRead (/)
; Prompt for file to be inserted
(if (= 1 (getvar “FILEDIA”))
(setq FileToRead (getfiled “File to Read” “” “TXT” 12))
;Else
(progn
(\n princ “Set variable FILEDIA to 1 then try again.”)
(setq FileToRead nil)
);End progn
);End if
)
;;; Save modes
;;;
(defun MODES (a)
(setq MLST ‘())
(repeat (length a)
(setq MLST (append MLST (list (list (car a) (getvar (car a))))))
(setq a (cdr a))
)
;;; Restore modes
;;;
(defun MODER ()
(repeat (length MLST)
(setvar (caar MLST) (cadar MLST))
(setq MLST (cdr MLST))
)
)
;;; Ascii Text error handler
;;;
(defun at_err (st) ; If an error (such as CTRL-C) occurs
; while this command is active…
(if (and (/= st “Function cancelled”)
(/= st “quit / exit abort”)
)
(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)
)
(defun asctxt (/)
(setq olderr *error* *error* at_err)
(modes ‘(“BLIPMODE” “CMDECHO” “HIGHLIGHT”))
; Prompt for file to be inserted
(while (null rtfile)
(if (null at_fnm)
(if (= 1 (getvar “FILEDIA”))
(setq rf (getfiled “File to Read” “” “” 12))
(progn
(initget 1)
(princ “\nFile to read (including extension): “)
(setq rf (getstring))
)
)
(if (= 1 (getvar “FILEDIA”))
(setq rf (getfiled “File to Read” at_fnm “” 12))
(progn
(princ “\nFile to read (including extension)/<“)
(princ (strcat at_fnm “>: “))
(setq rf (getstring))
)
)
)
(if (= rf nil) (exit))
(if (= rf 1)
(if (null at_fnm)
(progn
(initget 1)
(princ “\nFile to read (including extension): “)
(setq rf (getstring))
)
(progn
(princ “\nFile to read (including extension)/<“)
(princ (strcat at_fnm “>: “))
(setq rf (getstring))
)
)
)
(if (and (= rf “”) (/= nil at_fnm))
(setq rf at_fnm)
)
(setq rfa (findfile rf))
(if (= “~” rf)
(progn
(setq rfa nil)
(setq rtfile nil)
)
)
(if rfa
(progn
(setq at_fnm rfa)
(if (null (setq rtfile (open rfa “r”)))
(princ (strcat
“\n\tFile found, but couldn’t open ” at_fnm ” for reading. “))
)
)
(if (/= “~” rf)
(if (and (< 4 (strlen rf))
(/= (substr rf (- (strlen rf) 3) 1) “.”)
)
(princ “\nFile not found. Extension may be missing.”)
(princ “\nFile not found. “)
)
)
)
)
(setq cont T)
(if (= “Yes” (getkword “\nSet up columns?
(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)
)
;(defun c:at () (asctxt))
(defun c:asctext () (asctxt))
(princ “\n ASCTEXT loaded.”)
(princ)
(defun C:TBLIN ()
;;Select file using a dialog box.
(setq RpFileName
(getfiled “Select file to incorporate” “/acad/support/” “txt” 8)
)
;;Open the file.
(setq FileNum (open RpFileName “r”))
;;Test for an empty file.
(setq LineFile (read-line FileNum))
;;Getting data to Autocad.
(while (/= LineFile nil)
(setq LineFile (read-line FileNum)
(princ LineFile)
)
)
)