乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 79|回复: 19

[编程交流] 提取三维多段线坐标

[复制链接]
ARV

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:17:11 | 显示全部楼层 |阅读模式
你好
有人知道从三维多段线提取x、y、z顶点数据并将其导出到的方法吗。csv(或.txt文件)
 
ASMI的3cord工具与我想要的很接近
 
(我不允许发布链接)
 
遗憾的是,这在AutoCAD 2004中不起作用,并且不会输出到文件。
 
提前感谢,
安得烈
回复

使用道具 举报

0

主题

252

帖子

290

银币

限制会员

铜币
-8
发表于 2022-7-6 06:22:35 | 显示全部楼层
你可以用VBA写一些非常简单的东西。
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-6 06:25:56 | 显示全部楼层
这是可行的,但需要进一步完善。
 
  1. (defun c:3csv (/ cPl cFmn fVar pLst cAns *error*)
  2. (vl-load-com)
  3. (defun *error*(msg)
  4.    (if fVar(close fVar))
  5.    (princ)
  6.    ); end of *error*
  7. (defun Extract_3DPoly_Vertexes(Ent / cLst oLst)
  8.    (if(= 'ENAME(type Ent))
  9.      (setq Ent(vlax-ename->vla-object Ent))
  10.      ); end if
  11.    (if(= "AcDb3dPolyline"(vla-get-ObjectName Ent))
  12.      (progn
  13.        (setq cLst(vlax-safearray->list
  14.             (vlax-variant-value
  15.               (vla-get-Coordinates Ent))))
  16. (while cLst
  17.   (setq oLst(cons
  18.               (list
  19.                 (car cLst)
  20.                 (cadr cLst)
  21.                 (nth 2 cLst))
  22.               oLst)
  23.         ); end setq
  24.   (repeat 3(setq cLst(cdr cLst)))
  25.    ); end while
  26. (reverse oLst)
  27. ); end progn
  28.      ); end if
  29.    ); end of Extract_3DPoly_Vertexes
  30. (if(and
  31.       (setq cPl(entsel "\nSelect 3D-Polyline > "))
  32.       (= "POLYLINE"(cdr(assoc 0(entget(setq cPl(car cPl))))))
  33.       ); and
  34.    (progn
  35.      (setq fVar(open(setq cFmn(strcase(strcat(getvar "DWGPREFIX")
  36.            (vl-filename-base(getvar "DWGNAME")) ".csv"))) "a")
  37.     pLst(Extract_3DPoly_Vertexes cPl)
  38.    ); end setq
  39.      (write-line "X;Y;Z" fVar)
  40.      (foreach pt pLst
  41.   (write-line
  42.     (strcat(rtos(car pt))";"(rtos(cadr pt))";"(rtos(last pt)))
  43.     fVar)
  44.        ); end foreach
  45.       (close fVar)
  46.      (alert(strcat "\nCSV File location: " cFmn))
  47.      ); end progn
  48.    (princ "<!> It isn't 3D-Polyline <!> ")
  49.    ); end if
  50. (princ)
  51. ); end of c:3csv
回复

使用道具 举报

ARV

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:28:03 | 显示全部楼层
ASMI,
 
非常感谢,这正是我想要的。
我确实注意到,在输出文件中,值用分号而不是逗号分隔。这有什么原因吗?
我已经设法和你的*玩了。lsp将输出值用逗号分隔,这似乎确实有效。
我还在开头加了一点描述,在结尾加了一行,提醒我键入什么命令。我已附上*。lsp适用于任何其他可能觉得有用的人。
 
  1. ;;;--------------------------------------------------------------------------;
  2. ;;; DESCRIPTION
  3. ;;;   This is a utility that exports the X,Y,Z co-ordinates of the selected 3D polyline to a *.csv file.
  4. ;;;   The *.csv file is saved in the same folder as the autocad *.DWG with the same file name prefix.
  5. ;;;   e.g. the CSV file created from a 3d polyline extracted from "Example.dwg" would be named "Example.csv"
  6. ;;;   
  7. ;;;   Thank you to ASMI for writing this .lsp
  8. ;;;   
  9. (defun c:3csv (/ cPl cFmn fVar pLst cAns *error*)
  10. (vl-load-com)
  11. (defun *error*(msg)
  12.    (if fVar(close fVar))
  13.    (princ)
  14.    ); end of *error*
  15. (defun Extract_3DPoly_Vertexes(Ent / cLst oLst)
  16.    (if(= 'ENAME(type Ent))
  17.      (setq Ent(vlax-ename->vla-object Ent))
  18.      ); end if
  19.    (if(= "AcDb3dPolyline"(vla-get-ObjectName Ent))
  20.      (progn
  21.        (setq cLst(vlax-safearray->list
  22.            (vlax-variant-value
  23.              (vla-get-Coordinates Ent))))
  24.    (while cLst
  25.      (setq oLst(cons
  26.              (list
  27.            (car cLst)
  28.            (cadr cLst)
  29.            (nth 2 cLst))
  30.              oLst)
  31.        ); end setq
  32.      (repeat 3(setq cLst(cdr cLst)))
  33.       ); end while
  34.    (reverse oLst)
  35.    ); end progn
  36.      ); end if
  37.    ); end of Extract_3DPoly_Vertexes
  38. (if(and
  39.       (setq cPl(entsel "\nSelect 3D-Polyline > "))
  40.       (= "POLYLINE"(cdr(assoc 0(entget(setq cPl(car cPl))))))
  41.       ); and
  42.    (progn
  43.      (setq fVar(open(setq cFmn(strcase(strcat(getvar "DWGPREFIX")
  44.           (vl-filename-base(getvar "DWGNAME")) ".csv"))) "a")
  45.        pLst(Extract_3DPoly_Vertexes cPl)
  46.       ); end setq
  47.      (write-line "X,Y,Z" fVar)
  48.      (foreach pt pLst
  49.      (write-line
  50.        (strcat(rtos(car pt))","(rtos(cadr pt))","(rtos(last pt)))
  51.        fVar)
  52.        ); end foreach
  53.       (close fVar)
  54.      (alert(strcat "\nCSV File location: " cFmn))
  55.      ); end progn
  56.    (princ "<!> It isn't 3D-Polyline <!> ")
  57.    ); end if
  58. (princ)
  59. ); end of c:3csv
  60. (princ "\nType 3csv to run")

再次感谢大家,
安得烈
3csv。lsp
回复

使用道具 举报

18

主题

434

帖子

422

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
94
发表于 2022-7-6 06:32:26 | 显示全部楼层
:D和其他文字:“Asmi,您最好注释您的代码”:D
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-6 06:35:40 | 显示全部楼层
>抗逆转录病毒
 
 
将MS Excel单元格分开(尝试在Excel中打开带有逗号和半列的文件)是为了获得分布坐标。
 
>福卡罗
 
 
你说得有点对,我对代码的评论不太好。但在本例中,我将此代码视为试用代码,但如果它满足要求,则保持原样。
回复

使用道具 举报

0

主题

2

帖子

2

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 06:38:28 | 显示全部楼层
嗨,asmi和ARV,
感谢Asmi的lisp和ARV的评论\描述。
你能告诉我如何在这个CSV中再添加一个数据吗?这是线的层名称。我们可以选择多条线而不是总是选择单行吗。你能告诉我吗?我的Lisp程序不太好,所以我需要你的帮助。
感谢您的帮助。
回复

使用道具 举报

6

主题

249

帖子

247

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 06:39:48 | 显示全部楼层
 
这个程序不适合我。我得到的只是工作表前三个单元格中的alpha x y z,后面没有坐标?
我没有以任何方式修改代码。它写入正确的目录位置。有什么线索吗?
回复

使用道具 举报

0

主题

2

帖子

2

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 06:44:56 | 显示全部楼层
;;; 试试这个这是alex的原作
 
  1. ;;;--------------------------------------------------------------------------;
  2. ;;; DESCRIPTION
  3. ;;; This is a utility that exports the X,Y,Z co-ordinates of the selected 3D polyline to a *.csv file.
  4. ;;; The *.csv file is saved in the same folder as the autocad *.DWG with the same file name prefix.
  5. ;;; e.g. the CSV file created from a 3d polyline extracted from "Example.dwg" would be named "Example.csv"
  6. ;;;
  7. ;;; Thank you to ASMI for writing this .lsp
  8. ;;;
  9. (defun c:3csv (/ cPl cFmn fVar pLst cAns *error*)
  10. (vl-load-com)
  11. (defun *error*(msg)
  12. (if fVar(close fVar))
  13. (princ)
  14. ); end of *error*
  15. (defun Extract_3DPoly_Vertexes(Ent / cLst oLst)
  16. (if(= 'ENAME(type Ent))
  17. (setq Ent(vlax-ename->vla-object Ent))
  18. ); end if
  19. (if(= "AcDb3dPolyline"(vla-get-ObjectName Ent))
  20. (progn
  21. (setq cLst(vlax-safearray->list
  22. (vlax-variant-value
  23. (vla-get-Coordinates Ent))))
  24. (while cLst
  25. (setq oLst(cons
  26. (list
  27. (car cLst)
  28. (cadr cLst)
  29. (nth 2 cLst))
  30. oLst)
  31. ); end setq
  32. (repeat 3(setq cLst(cdr cLst)))
  33. ); end while
  34. (reverse oLst)
  35. ); end progn
  36. ); end if
  37. ); end of Extract_3DPoly_Vertexes
  38. (if(and
  39. (setq cPl(entsel "\nSelect 3D-Polyline > "))
  40. (= "POLYLINE"(cdr(assoc 0(entget(setq cPl(car cPl))))))
  41. ); and
  42. (progn
  43. (setq fVar(open(setq cFmn(strcase(strcat(getvar "DWGPREFIX")
  44. (vl-filename-base(getvar "DWGNAME")) ".csv"))) "a")
  45. pLst(Extract_3DPoly_Vertexes cPl)
  46. ); end setq
  47. (write-line "X,Y,Z" fVar)
  48. (foreach pt pLst
  49. (write-line
  50. (strcat(rtos(car pt))","(rtos(cadr pt))","(rtos(last pt)))
  51. fVar)
  52. ); end foreach
  53. (close fVar)
  54. (alert(strcat "\nCSV File location: " cFmn))
  55. ); end progn
  56. (princ "<!> It isn't 3D-Polyline <!> ")
  57. ); end if
  58. (princ)
  59. ); end of c:3csv
  60. (princ "\nType 3csv to run")
回复

使用道具 举报

6

主题

249

帖子

247

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 06:47:31 | 显示全部楼层
 
由此产生的xls文件如下所示
 
X Y Z
X Y Z
 
alpha如上所述,完全没有coords(2000 office premium中的Xcell),带Acad 8(17.1s)
不明白为什么标题下没有坐标?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 18:32 , Processed in 0.397850 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表