Here is a lisp routine I use to read in cvs data that for fire alarm calculations. It draws a table [as line work, not as table objects] with the data. Also attached is a typical data file. The data should be saved as a .txt file to match the lisp routine. This is written to work in model space and to scale the blocks that make up the table based on the value of DIMSCALE.
(defun c:nac (/ counter1 current drop ds file_name insert_point insert_x insert_y OK old_ortho
old_osmode opened string_list text_line temp_point temp_y
)
(defun *error* (msg)
(prompt (strcat "\n Error--> " msg))
(setvar "orthomode" old_ortho)
(setvar "osmode" old_osmode)
(princ)
)
(defun parse_string
(string_in delimiter / position_1 position_2 list_out)
(setq position_2 1)
(while (setq position_1
(vl-string-search delimiter string_in position_1)
)
(if (= position_2 1)
(setq
list_out (cons (substr string_in position_2 position_1)
list_out
)
)
(setq list_out (cons (substr string_in
position_2
(- (1+ position_1) position_2)
)
list_out
)
)
)
(setq position_2 (1+ (+ (strlen delimiter) position_1)))
(setq position_1 (+ position_1 (strlen delimiter)))
)
(reverse
(setq list_out (cons (substr string_in position_2) list_out))
)
)
(defun pr_ss (a_point a_distance) ; gets ss for box ((x-apnt),(y-apnt)) to ((x+apnt),(y+apnt))
(if (vl-string-search "BRICSCAD" (strcase (getvar "acadver"))) ; Bricscad fails for small apertures
(if (< a_distance 0.001) (setq a_distance 0.001))
)
(ssget "c"
(list (- (car a_point) a_distance)
(- (cadr a_point) a_distance)
)
(list (+ (car a_point) a_distance)
(+ (cadr a_point) a_distance)
)
)
)
(defun process (pr_point pr_text / pr_offset pr_selset pr_counter pr_entity
)
(setq pr_offset (* ds 0.06)) ; set the search area
(setq pr_selset (pr_ss pr_point pr_offset))
; get selection set in search area
(if pr_selset
(progn
(setq pr_counter (sslength pr_selset))
; get selection set length
(while (> pr_counter 0) ; loop through items
(setq pr_counter (1- pr_counter)) ; decrement counter
(setq pr_entity (entget (ssname pr_selset pr_counter)))
; get the entity
(if (= (cdr (assoc 0 pr_entity)) "TEXT") ;if it's text...
(progn
(setq pr_entity (subst (cons 1 pr_text)
(assoc 1 pr_entity)
pr_entity
)
)
(entmod pr_entity) ; else update entity color and value
)
)
)
)
)
)
(setvar "cmdecho" 0)
(setq old_ortho (getvar "orthomode"))
(setvar "orthomode" 0)
(setq old_osmode (getvar "osmode"))
(setvar "osmode" 0)
(setq ds (getvar "dimscale"))
(setq text_height (* ds 0.09375))
(if (setq
file_name (getfiled "Select NAC configuration file to read..."
(getvar "dwgprefix")
"txt"
128
)
)
(progn
(setq insert_point (getpoint "\n Select point for data box: "))
(setq insert_x (car insert_point))
(setq insert_y (cadr insert_point))
(setq opened (open file_name "r"))
(setq OK 1)
(setq current 0.0)
(setq counter1 0)
(while (and (setq text_line (read-line opened))
OK
)
(setq counter1 (1+ counter1))
(if (= counter1 1)
(progn
(if (= (substr text_line 1 8) "Device #")
(progn
(command "insert" "E_NAC_block_1" "PS" ds insert_point ds ds 0.0
)
(command "_explode" "last")
)
(progn
(setq OK nil)
)
)
)
(progn
(setq string_list (parse_string text_line ","))
(setq temp_y (- insert_y
(+ (* 3.0 text_height)
(* 2.0 text_height counter1)
)
)
)
(command "insert"
"E_NAC_block_2"
"PS"
ds
(list insert_x temp_y)
ds
ds
0.0
)
(command "_explode" "last")
(setq temp_y (+ temp_y (* ds -0.09375000)))
(setq temp_point
(list (+ insert_x (* ds 0.22812839))
temp_y
0.0
)
)
(process temp_point (nth 0 string_list))
(setq temp_point
(list (+ insert_x (* ds 1.11951417))
temp_y
0.0
)
)
(process temp_point (nth 1 string_list))
(setq temp_point
(list (+ insert_x (* ds 2.17027974))
temp_y
0.0
)
)
(process temp_point (nth 2 string_list))
(setq current (+ current (atof (nth 2 string_list))))
(setq temp_point
(list (+ insert_x (* ds 2.94529610))
temp_y
0.0
)
)
(process temp_point (rtos current 2 3))
(setq temp_point
(list (+ insert_x (* ds 3.72031246))
temp_y
0.0
)
)
(process temp_point (strcat (nth 3 string_list) "'"))
(setq temp_point
(list (+ insert_x (* ds 4.49532882))
temp_y
0.0
)
)
(process temp_point (strcat (nth 4 string_list) "'"))
(setq temp_point
(list (+ insert_x (* ds 5.27034519))
temp_y
0.0
)
)
(process temp_point (nth 6 string_list))
(setq temp_point
(list (+ insert_x (* ds 6.04536155))
temp_y
0.0
)
)
(process temp_point (nth 7 string_list))
)
)
)
(close opened)
(if OK
(progn
(setq temp_y (- insert_y
(+ (* 5.0 text_height)
(* 2.0 text_height counter1)
)
)
)
(command "insert"
"E_NAC_block_3"
"PS"
ds
(list insert_x temp_y)
ds
ds
0.0
)
(command "_explode" "last")
(setq temp_y (+ temp_y (* ds -0.09375000)))
(setq drop (/ (- 20.4 (atof (nth 6 string_list))) 0.2040))
(setq temp_point
(list (+ insert_x (* ds 5.27034519))
temp_y
0.0
)
)
(process temp_point (strcat (rtos drop 2 2) "%"))
(setq drop (/ (- 20.4 (atof (nth 7 string_list))) 0.2040))
(setq temp_point
(list (+ insert_x (* ds 6.04536155))
temp_y
0.0
)
)
(process temp_point (strcat (rtos drop 2 2) "%"))
(setq min_point (list (- insert_x (* 0.01 ds))
(+ insert_y (* 0.01 ds))
)
)
(setq
max_point (list (+ insert_x (* (+ 6.43286973 0.01) ds))
(- temp_y (+ text_height (* 0.01 ds)))
)
)
)
(alert "Invalid text file")
)
)
)
(setvar "orthomode" old_ortho)
(setvar "osmode" old_osmode)
(princ)
)
Device #,Device Name,Current Draw,Distance Between,Distance From Source,AWG10,AWG12,AWG14,AWG16,AWG18
1,P2R75,0.176,31,31,20.33,20.29,20.23,20.12,19.96
2,P2R75,0.176,23,54,20.29,20.22,20.12,19.96,19.69
3,SR15,0.066,13,67,20.27,20.20,20.08,19.88,19.58
4,P2R1575,0.1,27,94,20.24,20.14,19.99,19.75,19.37
5,SR15,0.066,5,99,20.23,20.14,19.98,19.73,19.34
6,SR15,0.066,17,116,20.22,20.12,19.95,19.68,19.25
7,P2R1575,0.1,25,141,20.21,20.09,19.91,19.61,19.15
8,P2R1575,0.1,25,166,20.20,20.07,19.88,19.57,19.08
9,SR15,0.066,21,187,20.19,20.07,19.87,19.56,19.06