- 积分
- 1276
- 明经币
- 个
- 注册时间
- 2024-3-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
因为课题需要,需要将CAD中的某个类型的文本文字导出到已经打开的excel中,在excel中编辑后,输入命令,将选定的excel中的文字导入AutoCAD中,要求求autoCAD中文字位置不发生变化,只是内容变化。
下面的程序只能实现导出具体到excel文件功能,但是导入函数报错:
通过xyz坐标将文字导出到excel, excel文字导出到CAD的程序,现在可以从CAD导出,但是目前没法导入。最佳的方式是将文件导出到已经打开excel中,然后在excel中修改后再导回CAD中。
导出函数
(defun c:EXTCSV (/ ss i f ename text pos)
(setq ss (ssget "X" '((0 . "TEXT,MTEXT"))))
(if ss
(progn
(setq f (open "D:/autocad_text.csv" "w"))
(if f
(progn
(write-line "TextString,X,Y,Z" f)
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i))
(setq ename (ssname ss i))
(setq text (cdr (assoc 1 (entget ename))))
(setq pos (cdr (assoc 10 (entget ename))))
(write-line (strcat text "," (rtos (car pos)) "," (rtos (cadr pos)) "," (rtos (caddr pos))) f)
)
(close f)
(princ "\nText has been exported to D:/autocad_text.csv")
)
(princ "\nFailed to open file for writing.")
)
)
(princ "\nNo text found in the drawing.")
)
(princ)
)
导入函数出错
(defun c:IMTCSV (/ f line fields text pos)
(setq f (open "D:/autocad_text.csv" "r"))
(if f
(progn
(read-line f) ; Skip the header line
(while (setq line (read-line f))
(setq fields (strtok line ","))
(setq text (nth 0 fields))
(setq pos (list (atof (nth 1 fields)) (atof (nth 2 fields)) (atof (nth 3 fields))))
(command "TEXT" pos "" "" text)
)
(close f)
(princ "\nText has been imported from D:/autocad_text.csv")
)
(princ "\nFailed to open file for reading.")
)
(princ)
)
|
|