Tblin AutoLisp Modes

(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)
)
)
)

Similar Posts

  • vsnap lisp

    (DEFUN C:VSNAP (/) ; Sept. 25,97. By V.Mendez ; This function centers an object between two parallel lines. (SETVAR “CMDECHO” 0) (SETQ SelObj (ENTSEL “\nSelect Object : “)) (SETQ BPoint (GETPOINT “\nBase Point : “)) (COMMAND “OSNAP” “NONE”) (COMMAND “OSNAP” “NEA”) (SETQ Point1 (GETPOINT “\nFirst Point [nearest] : “)) (COMMAND “OSNAP” “PER”) (SETQ Point2 (GETPOINT…

  • Block AutoLISP Shortcuts

    ;;; SHORCUTS BY V. MENDEZ ;SHOWS THE BLOCK NAME OF AN ENTITY (DEFUN C:BB(/ bb name) (SETQ bb(entget(car(entsel)))) (SETQ name (cdr(assoc 2 bb))) (SETQ name (strcat “Block Name… ” name)) (ALERT name) (princ) ) ;SHOWS THE LAYER NAME OF AN ENTITY (DEFUN C:CC(/ bb name) (SETQ bb(entget(car(entsel)))) (SETQ name (cdr(assoc 8 bb))) (SETQ name (strcat…

  • Legend AutoLisp

    (defun C:LEGEND () (prompt “\nBuilding legend list…\n”) ;Set variable to get the first element of table. (setq Frst T) (setq Counter 0) (setq CountBlk 0) ;Get all block names. (while (setq Tbdata (tblnext “BLOCK” Frst)) (setq Bname (dxf 2 Tbdata)) ;print all block names. (if (/= Bname nil) ;Discard dimension blocks. (if (/= “*” (substr…

  • Plocky Lisp

    (Defun FC (Func N Xo dx) ( (Setq LP ‘()) (Setq Int (/ dx N) (Setq x (-Xo Int)) (Repeat (+ N 1) (Setq x (+x Int)) (Setq y (FuncA x)) (Setq LPP (List x y)) (Setq LP (Cons LPP LP)) ) ) ) (Defun FuncA (V) (* V V) ) (Defun DrawF (ListP) (Setq…

  • Nine Algorithms That Changed the World

    Nine Algorithms That Changed the World In the realm of computer science, algorithms reign supreme. They are the step-by-step procedures that enable computers to solve problems and make decisions.1 Some algorithms have had such a profound impact on the field that they have become essential tools for programmers and researchers alike. In this article, we…