- (defun c:ExportTextToCSV (/ ali1 ali2 ent f fname fpath height i ss style text width)
- (setq ss (ssget '((0 . "TEXT,MTEXT"))))
- (if ss
- (progn
- (setq fpath (getvar "DWGPREFIX"))
- (setq fname (strcat fpath (vl-filename-base (getvar "DWGNAME")) ".csv"))
- (setq f (open fname "w"))
- (write-line "Content,Style,Alignment,Height,WidthFactor" f)
- (setq i 0)
- (repeat (sslength ss)
- (setq ent (entget (ssname ss i)))
- (setq i (+ i 1))
- (setq text (cdr (assoc 1 ent)))
- (setq style (cdr (assoc 7 ent)))
- (setq ali1 (cdr (assoc 72 ent)))
- (setq ali2 (cdr (assoc 73 ent)))
- (setq height (cdr (assoc 40 ent)))
- (setq width (cdr (assoc 41 ent)))
- (write-line (strcat text "," style "," (itoa ali1) "," (itoa ali2) "," (rtos height) "," (rtos width)) f)
- )
- (close f)
- (princ "\n导出完成。")
- )
- (princ "\n没有选择任何文字对象。")
- )
- (princ)
- )
- (defun c:ImportTextFromCSV (/ ali1 ali2 data f fname fpath gd kgb line pt wz zt)
- (setq fpath (getvar "DWGPREFIX"))
- (setq fname (strcat fpath (vl-filename-base (getvar "DWGNAME")) ".csv"))
- (setq f (open fname "r"))
- (if f
- (progn
- (read-line f)
- (while (setq line (read-line f))
- (setq data (read (strcat "(" (vl-string-translate "," " " line) ")")))
- (setq text (vl-princ-to-string (nth 0 data)))
- (setq style (vl-princ-to-string (nth 1 data)))
- (setq ali1 (nth 2 data))
- (setq ali2 (nth 3 data))
- (setq height (nth 4 data))
- (setq width (nth 5 data))
- (setq pt (getpoint "\n指定插入点:"))
- (entmake(list '(0 . "text")'(50 . 0.0) (cons 10 pt)(cons 11 pt)(cons 1 text)(cons 7 style)(cons 40 height)'(6 . "Continuous")(cons 41 width)(cons 72 ali1)'(210 0.0 0.0 1.0)'(100 . "AcDbText")(cons 73 ali2)))
- )
- (close f)
- (princ "\n导入完成。")
- )
- (princ "\n未找到CSV文件。")
- )
- (princ)
- )
|