CAD lisp 程序,选择所有类型多段线,输出其上点的x,y,z坐标,多段线id图层名称,到txt
时间: 2024-03-20 15:41:11 浏览: 164
CAD多段线导出散点数据lisp程序
5星 · 资源好评率100%
好的,以下是一个选择所有类型的多段线并输出其上点的x,y,z坐标、多段线ID、图层名称到txt文件的Lisp程序:
```
(defun c:outputpoints ()
(setq ss (ssget "_X" '((0 . "LWPOLYLINE") (0 . "POLYLINE"))))
(setq cnt 0)
(setq ptstr "")
(while (< cnt (sslength ss))
(setq ent (ssname ss cnt))
(setq cnt (1+ cnt))
(setq vertices (vlax-invoke-method ent 'vertices))
(setq cnt2 0)
(while (< cnt2 (vlax-get-property vertices 'count))
(setq pt (vlax-get-property (vlax-invoke-method vertices 'item cnt2) 'coordinates))
(setq cnt2 (1+ cnt2))
(setq ptstr (strcat ptstr (rtos (car pt) 2 6) "," (rtos (cadr pt) 2 6) "," (rtos (caddr pt) 2 6) "," (itoa (vla-get-ObjectID ent)) "," (cdr (assoc 8 (entget ent)))) "\n")
)
)
(setq filename (getfiled "Save" "" "output.txt" 0))
(setq file (open filename "w"))
(write-line "X,Y,Z,ID,Layer" file)
(write-line ptstr file)
(close file)
(princ "Points output to file: " filename)
)
```
您可以将上述代码复制到Lisp编辑器中,然后在AutoCAD中输入"APPLOAD"命令,加载Lisp文件,最后输入"OUTPUTPOINTS"命令即可选择所有类型的多段线并输出其上点的x,y,z坐标、多段线ID、图层名称到txt文件中。程序会提示您选择存储输出文件的路径和文件名。
阅读全文