乐筑天下

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

[编程交流] 合并或连接2个或多个多段

[复制链接]

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 11:12:24 | 显示全部楼层 |阅读模式
你好,这是我的第一篇帖子,所以我要把它做成一个大文章。我想向大家提出一个挑战,
在工作中,我们使用多段线来定义空间。每个多边形表示一个具有房间编号的空间,房间编号链接为具有扩展数据的块。每个多段线与相邻的多段线重叠。有点像你家里的房间,每条多段线像拼图一样拼合在一起,完成了一幅整体图。
我想要一个程序,通过删除重叠顶点,将两条或多条多段线合并为一条多段线。在其最简单的形式中,图2是相互对接的矩形多边形。然后,一条多段线的两个垂直方向与另一条多段线的两个垂直方向完全匹配。
然后,我想删除这些重叠的垂直,并创建一个新的(一个更大的多段线),只有外部边界。
我知道如何捕捉每个垂直点列表,并且知道如何识别重叠的点。但我不知道如何只捕捉外部顶点,并在这些剩余顶点的基础上创建一个新的多边形。
不幸的是,我不得不走另一条路,将它们调整为区域,并使用union命令,然后将它们转换回多段线。理论上,它可以工作,但对于不规则形状的多段线,它失败了。
非常感谢。
 
  1. [font=Times New Roman](Defun C:Merge ()[/font]
  2. [font=Times New Roman] (vl-load-com)[/font]
  3. [font=Times New Roman] (IF         (/= (GETVAR "WORLDUCS") 1)[/font]
  4. [font=Times New Roman]               (setq ucsvar (getvar "ucsname"))[/font]
  5. [font=Times New Roman] )[/font]
  6. [font=Times New Roman] (vl-cmdf "DELOBJ" "1")                   ;If this is zero then the polylines remain if 1 they are removed[/font]
  7. [font=Times New Roman] (vl-cmdf "-layer" "s" poly-ten "")   ;make polyten current so the polyline is drawn correctly[/font]
  8. [font=Times New Roman] (SETQ a (car (entsel "\nSelect First polyline to merge:")))[/font]
  9. [font=Times New Roman] (SETQ bptlst nil)[/font]
  10. [font=Times New Roman] (vl-cmdf "ucs" "")[/font]
  11. [font=Times New Roman] ;(SETQ plst (ENTGET a))[/font]
  12. [font=Times New Roman] ;(FOREACH n plst[/font]
  13. [font=Times New Roman] ;  (IF      (= 10 (CAR n))[/font]
  14. [font=Times New Roman] ;    (SETQ bptlst (CONS (CDR n) bptlst))[/font]
  15. [font=Times New Roman] ;  )[/font]
  16. [font=Times New Roman] [/font]
  17. [font=Times New Roman] ;(vl-cmdf "erase" pdim "")[/font]
  18. [font=Times New Roman] (vl-cmdf "ucs" "r" ucsvar "")[/font]
  19. [font=Times New Roman] (setq b (car (entsel "\nSelect Second polyline to Merge:")))[/font]
  20. [font=Times New Roman] ;(SETQ bptlst nil)[/font]
  21. [font=Times New Roman] (vl-cmdf "ucs" "")[/font]
  22. [font=Times New Roman] ;(SETQ plst (ENTGET b))[/font]
  23. [font=Times New Roman] ;(FOREACH n plst[/font]
  24. [font=Times New Roman] ;  (IF      (= 10 (CAR n))[/font]
  25. [font=Times New Roman] ;    (SETQ bptlst (CONS (CDR n) bptlst))[/font]
  26. [font=Times New Roman] ;  )[/font]
  27. [font=Times New Roman] [/font]
  28. [font=Times New Roman] (vl-cmdf "LAYISO" A "") ;This needs to know what layer to isolate so feed it the polyline on poly-ten[/font]
  29. [font=Times New Roman] (vl-cmdf "region" a "")                      ;Turn polyline a into a region[/font]
  30. [font=Times New Roman] (setq a1 (ssget "L"))                                          ;now get region a[/font]
  31. [font=Times New Roman] (vl-cmdf "region" b "")                     ;turn polyline b into a region[/font]
  32. [font=Times New Roman] (setq b1 (ssget "L"))                                          ;now get region b[/font]
  33. [font=Times New Roman] (vl-cmdf "union" a1 b1 "")                               ;at this point the region is one and the overlap is gone[/font]
  34. [font=Times New Roman] (setq ename (entlast))                        ;now get the newly defined union[/font]
  35. [font=Times New Roman] (setq obj (vlax-ename->vla-object ename))[/font]
  36. [font=Times New Roman]                                                                               ;both of these are still regions[/font]
  37. [font=Times New Roman] (setq     centroid (vlax-safearray->list[/font]
  38. [font=Times New Roman]                                  (vlax-variant-value (vla-get-centroid obj))[/font]
  39. [font=Times New Roman]                                )[/font]
  40. [font=Times New Roman] )[/font]
  41. [font=Times New Roman] (vl-cmdf "-boundary" centroid "")  ;The boundary command asks for an internal point so give it the centroid[/font]
  42. [font=Times New Roman] (vl-cmdf "LAYUNISO")                    ;PUT IT BACK[/font]
  43. [font=Times New Roman] (entdel ename)                                    ;erase the region[/font]
  44. [font=Times New Roman] (setq plst (entget (ssname (ssget "L") 0)));this is getting the region and not the poly[/font]
  45. [font=Times New Roman] (FOREACH n plst[/font]
  46. [font=Times New Roman]   (IF       (= 10 (CAR n))[/font]
  47. [font=Times New Roman]     (SETQ bptlst (CONS (CDR n) bptlst))[/font]
  48. [font=Times New Roman]   )[/font]
  49. [font=Times New Roman] )[/font]
  50. [font=Times New Roman] (setq pdim (ssget "_CP" bptlst '((0 . "text")(8 . "dim"))))[/font]
  51. [font=Times New Roman] (setq pdim (ssget "_CP" bptlst '((0 . "text")(8 . "dim"))))             ;This gets the dimensions using crossing window unless the dimension is way off[/font]
  52. [font=Times New Roman] (vl-cmdf "erase" pdim "")[/font]
  53. [font=Times New Roman])[/font]
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:24:27 | 显示全部楼层
也许试着过度杀戮?
 
另请参见此处。
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 11:39:26 | 显示全部楼层
谢谢
李,我试试看
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 11:49:55 | 显示全部楼层
李,那是快捷菜单上的对吗?我想我们升级了,它消失了。
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-6 12:00:57 | 显示全部楼层
类型:ExpressTools。
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 12:10:44 | 显示全部楼层
很好,确实加载了程序。然后我输入了Overkill。我看看会怎么样。据我所知,Overkill消除了重复实体。我来看看。
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 12:16:54 | 显示全部楼层
好吧,我试着过度杀戮,但并不完全正确。它确实打开了一个对话框,我可以勾选要包括或排除的某些方面,然后当我选择两条多段线时,它会创建一条部分多段线,但它并不完整。
我想我将通过捕捉列表中的所有顶点来探索一条不同的路线,然后创建一个新的列表,排除重复的顶点,然后根据新列表创建一条新的多段线。
再次感谢。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 11:31 , Processed in 0.889498 second(s), 66 queries .

© 2020-2025 乐筑天下

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