通过csv文件绘图求助
<p>具体是这样,csv格式表格中每一行有名称,长度和宽度信息</p><p>要求用每一行数据绘制一张DXF格式图,图名称为表格中的名称,图纸内容为以表格中长度和宽度绘制的矩形。</p>
<p>举个例子,如果csv中有5行的话就要有5张DXF格式的图纸。希望是lisp写的,本人是菜鸟,刚接触,哪位大侠能帮助小弟一下,定当感激不尽。</p>
(defun c:tt()
(defun gxl-StrParse (Str Delimiter / SearchStr StringLen return n char nn)
(setq SearchStr Str)
(setq StringLen (strlen SearchStr) nn StringLen)
(setq return '())
(while (> StringLen 0)
(setq n 1)
(setq char (substr SearchStr 1 1))
(while (and (/= char Delimiter) (<= n nn))
(setq n (1+ n))
(setq char (substr SearchStr n 1))
) ;_ end of while
(setq return (cons (substr SearchStr 1 (1- n)) return))
(setq SearchStr (substr SearchStr (1+ n) StringLen))
(setq StringLen (strlen SearchStr))
) ;_ end of while
(if (= " " Delimiter)
(setq return (vl-remove"" return))
)
(reverse return)
)
(setq fn (getfiled "请输入文件名 :" "" "csv" 4))
(setq f (open fn "r"))
(while (setq zc (read-line f))
(setq zc (GXL-STRPARSE zc ","))
(setq fname (car zc)
L (cadr zc)
w (caddr zc)
)
(command "_.rectang"'(0 0 0) (strcat "@" l "," w))
(command "_.dxfout" fname "")
(command "erase" "all" "")
)
(close f)
)
程序要在空白图中运行
;ZZXXQQ 2010.11.8
(defun c:tt ( / fn f zc i zl)
(setvar "CMDECHO" 0)
(setq fn (if fn fn ""))
(if (setq fn (getfiled "请输入文件名 :" fn "csv" 4)) (progn
(setq f (open fn "r"))
(while (setq zc (read-line f))
(setq i 1 zl "(\"")
(repeat (strlen zc)
(setq zl (strcat zl (if (/= (setq txt (substr zc i 1)) ",") txt "\" \"")))
(setq i (1+ i))
)
(setq zl (strcat zl "\")") zc (read zl))
(command "_.UNDO" "BE")
(command "_.rectang" '(0 0 0) (strcat "@" (cadr zc) "," (caddr zc)))
(command "_.dxfout" (car zc) "")
(command "_.UNDO" "E" "_U")
)
(close f)
))
(setvar "CMDECHO" 1)
(princ)
)
页:
[1]