;;; TableIn.LSP 4/4/97 ; v ? 11/4/99 Fixed newtext to use current textstyle instead of curent layer for text style. ; v1.02 11/10/00 Fixed prompt to say ROW spacing. Was incorrectly asking for column spacing. ; v2.0 10/4/04 Changed to use only justification line. Separator definition line was redundant. ; Also now indicates what the justification is when prompting for location. ;;; ;;; Copyright 1997-2004 By J. Marsden DeLapp ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, see ; http://www.gnu.org/licenses/gpl.txt ; ; Or write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ; ;;; -------------------------------------------------------------- ;;; Table In LISP routine will take a text file and import it ;;; into a drawing while splitting each line into columns. ;;; ;;; First line in file indicates column locations and justification. ;;; EXAMPLE: ;;; ;;; C L L R E ;;; qty unit description price ;;; 1 e widget $13.95 ;;; 20 ft rope $102.05 ;;; 500 ea brick $0.33 ;;; 2 ea block $1.50 ;;; ;;; Note that the last column length is indicated with a final ;;; character (anything to make the line that many characters ;;; long). ; ; Note that use of the text command used assumes current style requires ; height to be input (no fixed text height). This should be fixed. ; ;------------------------ StripSPC ------------------------------------------ ;;;;strip off leading and trailing spaces if length is > 0 (defun stripspc ( tempstr / tchar) (if (> (strlen tempstr) 0) (progn ;; first strip leading spaces (setq tchar (substr tempstr 1 1)) ;get the first char (while (= tchar " ") (setq tempstr (substr tempstr 2)); strip the char (setq tchar (substr tempstr 1 1)) ;get the first char );while ;;now strip trailing spaces (if tempstr still exists) (if (> (strlen tempstr) 0) (progn (setq tchar (substr tempstr (strlen tempstr) 1)) ;get the last char (while (= tchar " ") (setq tempstr (substr tempstr 1 (1- (strlen tempstr))) ); strip the char (setq tchar (substr tempstr (strlen tempstr) 1)) ;get the last char );while ) ) ) ) (eval tempstr) ) ;*********************************************************** ;newtext will put the text in at a point using entmake ;will use current style and current layer ;uses textsize system variable if txtht argument is 0 (defun newtext ( txtpt text txtht) (if (= txtht 0) (setq txtht (getvar "textsize")) ) (entmake (list (0 . "TEXT") ;make a text entity (1 . text) ;text value (8 . (getvar "CLAYER"));put on current layer (10 . txtpt) ;insertion point (40 . txtht) ;text height (7 . (getvar "TEXTSTYLE"));use current text style )) );defun ;*********************************************************** ;------------------------ TABLEIN ------------------------------------------ (defun C:TableIN (/ cem colspc Fin pt1 yloc xloc lxloc rowspc txtline col clen just txtl1 txtl2 i tlen tempstr ncol nchars lcol ljust llen tchar ) (princ "Table In V2.00 Copyright 1997-2004 by J. Marsden DeLapp.") (setq olderr *error* *error* MDI_er ) (setq cem (getvar "cmdecho")) (setvar "cmdecho" 0) (command ".undo" "Mark")(princ "\nUNDO Mark set. ") (if (setq Fin (open (getfiled "Table input file" "" "txt" 0) "r")) (progn (setq txtl1 (read-line Fin);read 1st line i 1 ; set loop counter tempstr txtl1 ;set temp string tlen (strlen tempstr) ncol 0 ;number of columns nchars 0 ;count of field length ) (while (<= i tlen);step though each character (setq tchar (substr tempstr 1 1) ;get the first char tempstr (substr tempstr 2); strip the char nchars (1+ nchars) ;increase the field length count ) (if (/= tchar " ") (progn (setq ncol (1+ ncol) ; add to column count lcol (append lcol (list i)) ;add to list of col start locations ljust (append ljust (list (substr txtl1 i 1))) ;add justification to list llen (append llen (list nchars)) ;add to list of lengths nchars 0 ;reset count of field length ) ) ) (setq i (1+ i)) ) ;Reduce ncol count because the last character counted was the end of the last column, not a new column. (setq ncol (1- ncol)) ;strip off the first count (not the first length) and add the final count (setq llen (append (cdr llen) (list nchars))) (setq pt1 (getpoint (strcat "\nFirst column location (x & y), " (nth 0 ljust) " justified: " )) lxloc (append lxloc (list (car pt1))); start list of x locations yloc (cadr pt1) i 1 ) ;;Get the x location for the rest of the columns (while (< i ncol) (setq i (1+ i) pt1 (getpoint (strcat "\nX location of column # " (itoa i) ", " (nth (- i 1) ljust) " justified: ")) lxloc (append lxloc (list (car pt1))); add to list of x locations ) ) (setq rowspc (getdist "\nRow spacing: ")); set the row spacing (while (setq txtline (read-line Fin)) ;read a line (setq i 0);column counter, (nth) starts counting at 0 (while (< i ncol) (setq xloc (nth i lxloc) col (nth i lcol) ;set column char start clen (nth i llen) ;set length of column just (nth i ljust);set justification ) (if (= just "L") (setq just "BL")); not just left but bottom left (if (= (1+ i) ncol); if it is last one don't enter length (setq tempstr (stripspc (substr txtline col ))); pick out the field (setq tempstr (stripspc (substr txtline col clen))); pick out the field ) (if (/= tempstr "")(command ".text" "J" just (list xloc yloc) "" "" tempstr)) (setq i (1+ i));next column ) (setq yloc (- yloc rowspc)) ;down to next line );While read line (close Fin) );progn (princ "\nOpen file for input failed") );If Fin (setvar "cmdecho" cem) (setq *error* olderr) (princ) ) (prompt "\nType \"TableIn\" to start.") (princ)