layys 发表于 2023-6-2 09:35:50

导出线段的长度到excel

(defun c:tee ( / &a0 &dis1 &k1 &kw1 &ss1 &ss2)
(if (null vlax-dump-object) (vl-load-com) )
(princ "\n请选择曲线")
(setq &ss1 '("LINE" "LWPOLYLINE" "CIRCLE" "ARC" "HELIX" "ELLIPSE" "SPLINE" "POLYLINE"))
(if (setq &kw1 (ssget '((0 . "LINE,LWPOLYLINE,CIRCLE,ARC,HELIX,ELLIPSE,SPLINE,POLYLINE"))))
(progn
   (setq &ss2 '())
   (while (setq &k1 (ssname &kw1 0))
    (setq &kw1 (ssdel &k1 &kw1) &a0 (cdr (assoc 0 (entget &k1))))
    (setq &dis1 (vlax-curve-getDistAtParam &k1 (vlax-curve-getEndParam &k1)))
    (setq &ss2 (cons (cons &a0 &dis1) &ss2))
   );while
   (s1712061 &ss1 &ss2)
)
)
(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"))
(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
    (while (setq &dis1 (car &ss3))
   (setq &ss3 (cdr &ss3))
   (write-line (strcat &a0 "," (rtos &dis1)) ff)
    );while
    (write-line "" ff)
   )
);if
);while
(close ff)
)

dazuyishi1314 发表于 2023-6-2 13:00:48

试了没用啊。。。

p-3-ianlcc 发表于 2023-6-2 13:07:17

谢谢分享!
测试了一下
可以使用

孤独荒原狼 发表于 2023-6-2 14:00:42

CSV这个格式好。

hzyhzjjzh 发表于 2023-6-3 13:04:11

多谢楼主分享

zhangkui9070 发表于 2023-6-5 14:13:03

感谢大佬分享

jkop 发表于 2023-7-31 16:54:04

测试ok,对于电线电缆计算很直观,也能利用excel的特性加总、加乘,方便很多,感谢大佬分享。
页: [1]
查看完整版本: 导出线段的长度到excel