CAD lisp 程序,选择所有类型多段线,输出其上点的x,y,z坐标到txt
时间: 2024-03-20 14:41:09 浏览: 133
autocad中输出复合线的所有顶点坐标到一个txt文件中
好的,以下是一个选择所有类型的多段线并输出其上点的x,y,z坐标到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) "\n"))
)
)
(setq filename (getfiled "Save" "" "output.txt" 0))
(setq file (open filename "w"))
(write-line ptstr file)
(close file)
(princ "Points output to file: " filename)
)
```
您可以将上述代码复制到Lisp编辑器中,然后在AutoCAD中输入"APPLOAD"命令,加载Lisp文件,最后输入"OUTPUTPOINTS"命令即可选择所有类型的多段线并输出其上点的x,y,z坐标到txt文件中。程序会提示您选择存储输出文件的路径和文件名。
阅读全文