你好,这是我的第一篇帖子,所以我要把它做成一个大文章。我想向大家提出一个挑战,
在工作中,我们使用多段线来定义空间。每个多边形表示一个具有房间编号的空间,房间编号链接为具有扩展数据的块。每个多段线与相邻的多段线重叠。有点像你家里的房间,每条多段线像拼图一样拼合在一起,完成了一幅整体图。
我想要一个程序,通过删除重叠顶点,将两条或多条多段线合并为一条多段线。在其最简单的形式中,图2是相互对接的矩形多边形。然后,一条多段线的两个垂直方向与另一条多段线的两个垂直方向完全匹配。
然后,我想删除这些重叠的垂直,并创建一个新的(一个更大的多段线),只有外部边界。
我知道如何捕捉每个垂直点列表,并且知道如何识别重叠的点。但我不知道如何只捕捉外部顶点,并在这些剩余顶点的基础上创建一个新的多边形。
不幸的是,我不得不走另一条路,将它们调整为区域,并使用union命令,然后将它们转换回多段线。理论上,它可以工作,但对于不规则形状的多段线,它失败了。
非常感谢。
[font=Times New Roman](Defun C:Merge ()[/font][font=Times New Roman] (vl-load-com)[/font][font=Times New Roman] (IF (/= (GETVAR "WORLDUCS") 1)[/font][font=Times New Roman] (setq ucsvar (getvar "ucsname"))[/font][font=Times New Roman] )[/font][font=Times New Roman] (vl-cmdf "DELOBJ" "1") ;If this is zero then the polylines remain if 1 they are removed[/font][font=Times New Roman] (vl-cmdf "-layer" "s" poly-ten "") ;make polyten current so the polyline is drawn correctly[/font][font=Times New Roman] (SETQ a (car (entsel "\nSelect First polyline to merge:")))[/font][font=Times New Roman] (SETQ bptlst nil)[/font][font=Times New Roman] (vl-cmdf "ucs" "")[/font][font=Times New Roman] ;(SETQ plst (ENTGET a))[/font][font=Times New Roman] ;(FOREACH n plst[/font][font=Times New Roman] ; (IF (= 10 (CAR n))[/font][font=Times New Roman] ; (SETQ bptlst (CONS (CDR n) bptlst))[/font][font=Times New Roman] ; )[/font][font=Times New Roman] [/font][font=Times New Roman] ;(vl-cmdf "erase" pdim "")[/font][font=Times New Roman] (vl-cmdf "ucs" "r" ucsvar "")[/font][font=Times New Roman] (setq b (car (entsel "\nSelect Second polyline to Merge:")))[/font][font=Times New Roman] ;(SETQ bptlst nil)[/font][font=Times New Roman] (vl-cmdf "ucs" "")[/font][font=Times New Roman] ;(SETQ plst (ENTGET b))[/font][font=Times New Roman] ;(FOREACH n plst[/font][font=Times New Roman] ; (IF (= 10 (CAR n))[/font][font=Times New Roman] ; (SETQ bptlst (CONS (CDR n) bptlst))[/font][font=Times New Roman] ; )[/font][font=Times New Roman] [/font][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][font=Times New Roman] (vl-cmdf "region" a "") ;Turn polyline a into a region[/font][font=Times New Roman] (setq a1 (ssget "L")) ;now get region a[/font][font=Times New Roman] (vl-cmdf "region" b "") ;turn polyline b into a region[/font][font=Times New Roman] (setq b1 (ssget "L")) ;now get region b[/font][font=Times New Roman] (vl-cmdf "union" a1 b1 "") ;at this point the region is one and the overlap is gone[/font][font=Times New Roman] (setq ename (entlast)) ;now get the newly defined union[/font][font=Times New Roman] (setq obj (vlax-ename->vla-object ename))[/font][font=Times New Roman] ;both of these are still regions[/font][font=Times New Roman] (setq centroid (vlax-safearray->list[/font][font=Times New Roman] (vlax-variant-value (vla-get-centroid obj))[/font][font=Times New Roman] )[/font][font=Times New Roman] )[/font][font=Times New Roman] (vl-cmdf "-boundary" centroid "") ;The boundary command asks for an internal point so give it the centroid[/font][font=Times New Roman] (vl-cmdf "LAYUNISO") ;PUT IT BACK[/font][font=Times New Roman] (entdel ename) ;erase the region[/font][font=Times New Roman] (setq plst (entget (ssname (ssget "L") 0)));this is getting the region and not the poly[/font][font=Times New Roman] (FOREACH n plst[/font][font=Times New Roman] (IF (= 10 (CAR n))[/font][font=Times New Roman] (SETQ bptlst (CONS (CDR n) bptlst))[/font][font=Times New Roman] )[/font][font=Times New Roman] )[/font][font=Times New Roman] (setq pdim (ssget "_CP" bptlst '((0 . "text")(8 . "dim"))))[/font][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][font=Times New Roman] (vl-cmdf "erase" pdim "")[/font][font=Times New Roman])[/font]