yimiyangguang55
发表于 2024-3-7 23:18:12
大师,请教您一个问题,我有一个将CAD里面通过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)
)
yimiyangguang55
发表于 2024-3-7 23:36:50
这些都是超级实用的小程序,感谢分享
lidaxiu
发表于 2024-3-7 23:59:22
单纯的罗列数据虽有意义,但感觉不如把同类项数量相加,汇总到一起意义更大
lidaxiu
发表于 2024-3-8 00:08:44
ferious
发表于 2024-3-8 08:13:16
郎大师,此时此刻,我只想唱一首,《ONLY YOU》。不知是否可以?
22千里之外
发表于 2024-3-8 11:30:36
保存下了,感谢大师分享
ferious
发表于 2024-3-8 14:11:57
帮忙看下,报错
ferious
发表于 2024-3-8 14:19:54
附件如下,框选后出错
ferious
发表于 2024-3-8 14:22:32
好像选择过程不能空格,空格就会出错
ferious
发表于 2024-3-8 14:25:12
能否优化?