cad的插件lsp 计算统计所有线段长度 但是不能写入excel 求大神帮忙(内有代码)

(defun c:n()
(setq tleng 0)
(setq S (ssget '((0 . "CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE,ARC"))))
(setq n (sslength s))
(setq index (- n 1))
(repeat n (vl-load-com)
(setq ent (ssname s index))
(setq index (- index 1))
(setq curve-obj (vlax-ename->vla-object ent))
(setq leng (vlax-curve-getDistAtParam curve-obj (vlax-curve-getEndParam curve-obj) ) )
(setq tleng (+ tleng leng)) (princ leng) (princ "\n") )
(setq prscreemtext (strcat "\n总共计算" (itoa n) "个对象,总长度: " (rtos tleng 2 5)))
(princ prscreemtext) (princ) )

(defun s1712061 (&ss1 &ss2 / &a0 &dis1 &ss1 &ss2 &ss3 ff tr1 x y);写入长度到表格
(setq tr1 (strcat "D://" (rtos (* 1000000 (getvar "cdate")) 2 0) ".csv"))
(setq ff (open tr1 "w"));D盘表格Point
(while (setq &a0 (car &ss1))
(setq &ss1 (cdr &ss1))
(if (setq &ss3 (mapcar 'cdr (vl-remove-if-not '(lambda (X) (= &a0 (car x))) &ss2)))
(progn
(setq &ss3 (vl-sort &ss3 '(lambda (x y) (< x y))));长度从小到大
(while (setq &dis1 (car &ss3))
(setq &ss3 (cdr &ss3))
(write-line (strcat &a0 "," (rtos &dis1)) ff)
);while
(write-line "" ff)
)
);if
);while
(close ff)
)
大神,这个代码载入后,输入命令,运行没有错误,但是找不到相应的文件,不知道是不是没有运行成功还是文件没有保存在D盘呢?
非常感谢。

已为你修改,最后提示改为米。

(princ "\n程序:统计线段长度 命令:te")(defun C:TE (/ CURVE TLEN SS N SUMLEN) (vl-load-com) (setq SUMLEN 0) (setq SS (ssget '((0 . "CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE,ARC")))) (setq N 0) (repeat (sslength SS) (setq CURVE (vlax-ename->vla-object (ssname SS N))) (setq TLEN (vlax-curve-getdistatparam CURVE (vlax-curve-getendparam CURVE))) (setq SUMLEN (+ SUMLEN TLEN)) (setq N (1+ N))) (setq sumlen(/ sumlen 1000))(princ (strcat "\n共选择 " (itoa (sslength SS)) " 条线段. 线段总长: "(rtos SUMLEN 2 3) "米."))(princ) )
温馨提示:答案为网友推荐,仅供参考
相似回答