BLacy 发表于 2022-7-6 11:12:24

合并或连接2个或多个多段

你好,这是我的第一篇帖子,所以我要把它做成一个大文章。我想向大家提出一个挑战,
在工作中,我们使用多段线来定义空间。每个多边形表示一个具有房间编号的空间,房间编号链接为具有扩展数据的块。每个多段线与相邻的多段线重叠。有点像你家里的房间,每条多段线像拼图一样拼合在一起,完成了一幅整体图。
我想要一个程序,通过删除重叠顶点,将两条或多条多段线合并为一条多段线。在其最简单的形式中,图2是相互对接的矩形多边形。然后,一条多段线的两个垂直方向与另一条多段线的两个垂直方向完全匹配。
然后,我想删除这些重叠的垂直,并创建一个新的(一个更大的多段线),只有外部边界。
我知道如何捕捉每个垂直点列表,并且知道如何识别重叠的点。但我不知道如何只捕捉外部顶点,并在这些剩余顶点的基础上创建一个新的多边形。
不幸的是,我不得不走另一条路,将它们调整为区域,并使用union命令,然后将它们转换回多段线。理论上,它可以工作,但对于不规则形状的多段线,它失败了。
非常感谢。
 

(Defun C:Merge ()
(vl-load-com)
(IF         (/= (GETVAR "WORLDUCS") 1)
               (setq ucsvar (getvar "ucsname"))
)
(vl-cmdf "DELOBJ" "1")                   ;If this is zero then the polylines remain if 1 they are removed
(vl-cmdf "-layer" "s" poly-ten "")   ;make polyten current so the polyline is drawn correctly
(SETQ a (car (entsel "\nSelect First polyline to merge:")))
(SETQ bptlst nil)
(vl-cmdf "ucs" "")
;(SETQ plst (ENTGET a))
;(FOREACH n plst
;(IF      (= 10 (CAR n))
;    (SETQ bptlst (CONS (CDR n) bptlst))
;)


;(vl-cmdf "erase" pdim "")
(vl-cmdf "ucs" "r" ucsvar "")
(setq b (car (entsel "\nSelect Second polyline to Merge:")))
;(SETQ bptlst nil)
(vl-cmdf "ucs" "")
;(SETQ plst (ENTGET b))
;(FOREACH n plst
;(IF      (= 10 (CAR n))
;    (SETQ bptlst (CONS (CDR n) bptlst))
;)

(vl-cmdf "LAYISO" A "") ;This needs to know what layer to isolate so feed it the polyline on poly-ten
(vl-cmdf "region" a "")                      ;Turn polyline a into a region
(setq a1 (ssget "L"))                                          ;now get region a
(vl-cmdf "region" b "")                     ;turn polyline b into a region
(setq b1 (ssget "L"))                                          ;now get region b
(vl-cmdf "union" a1 b1 "")                               ;at this point the region is one and the overlap is gone
(setq ename (entlast))                        ;now get the newly defined union
(setq obj (vlax-ename->vla-object ename))
                                                                               ;both of these are still regions
(setq   centroid (vlax-safearray->list
                                  (vlax-variant-value (vla-get-centroid obj))
                              )
)
(vl-cmdf "-boundary" centroid "");The boundary command asks for an internal point so give it the centroid
(vl-cmdf "LAYUNISO")                  ;PUT IT BACK
(entdel ename)                                    ;erase the region
(setq plst (entget (ssname (ssget "L") 0)));this is getting the region and not the poly
(FOREACH n plst
   (IF       (= 10 (CAR n))
   (SETQ bptlst (CONS (CDR n) bptlst))
   )
)
(setq pdim (ssget "_CP" bptlst '((0 . "text")(8 . "dim"))))
(setq pdim (ssget "_CP" bptlst '((0 . "text")(8 . "dim"))))             ;This gets the dimensions using crossing window unless the dimension is way off
(vl-cmdf "erase" pdim "")
)

Lee Mac 发表于 2022-7-6 11:24:27

也许试着过度杀戮?
 
另请参见此处。

BLacy 发表于 2022-7-6 11:39:26

谢谢
李,我试试看

BLacy 发表于 2022-7-6 11:49:55

李,那是快捷菜单上的对吗?我想我们升级了,它消失了。

alanjt 发表于 2022-7-6 12:00:57

类型:ExpressTools。

BLacy 发表于 2022-7-6 12:10:44

很好,确实加载了程序。然后我输入了Overkill。我看看会怎么样。据我所知,Overkill消除了重复实体。我来看看。

BLacy 发表于 2022-7-6 12:16:54

好吧,我试着过度杀戮,但并不完全正确。它确实打开了一个对话框,我可以勾选要包括或排除的某些方面,然后当我选择两条多段线时,它会创建一条部分多段线,但它并不完整。
我想我将通过捕捉列表中的所有顶点来探索一条不同的路线,然后创建一个新的列表,排除重复的顶点,然后根据新列表创建一条新的多段线。
再次感谢。
页: [1]
查看完整版本: 合并或连接2个或多个多段