arden 发表于 2006-1-5 14:50:00

计算图斑面积时的岛

<P>我用SelectByPolygon方法进行选择时总是不能选到与边界相连的内部多边形(图形见付件),我在开发论坛问了一个月了也没人回答,希望这里能得到帮助,先谢谢</P>
<P>Sub selectPl()<BR>&nbsp;&nbsp;&nbsp; Dim ent As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Dim SelObj As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Dim NumSel As Integer<BR>&nbsp;&nbsp;&nbsp; Dim Coord As Variant<BR>&nbsp;&nbsp;&nbsp; Dim CoordCount As Integer<BR>&nbsp;&nbsp;&nbsp; Dim NewCoord() As Double<BR>&nbsp;&nbsp;&nbsp; Dim i As Integer<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim ssetObj As AcadSelectionSet<BR>&nbsp;&nbsp;&nbsp; On Error GoTo Err1:<BR>&nbsp;&nbsp;&nbsp; Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET2")<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; On Error Resume Next<BR>&nbsp;&nbsp;&nbsp; Do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.GetEntity ent, pnt, "选择多段线:"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Err Then Exit Sub<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If TypeName(ent) Like "IAcad*Polyline" Then Exit Do<BR>&nbsp;&nbsp;&nbsp; Loop<BR>&nbsp;&nbsp;&nbsp; <BR>If TypeName(ent) = "IAcadLWPolyline" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Coord = ent.Coordinates&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CoordCount = (UBound(Coord) + 1) / 2 '顶点数<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '定义新的顶点坐标数组<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim NewCoord(0 To (3 * CoordCount - 1)) As Double<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To UBound(Coord) - 1 Step 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewCoord((3 * i) / 2) = Coord(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewCoord((3 * i) / 2 + 1) = Coord(i + 1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewCoord((3 * i) / 2 + 2) = 0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next i<BR>ElseIf TypeName(ent) = "IAcadPolyline" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Coord = ent.Coordinates<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CoordCount = (UBound(Coord) + 1) / 3<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim NewCoord(0 To UBound(Coord)) As Double<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To UBound(Coord) - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewCoord(i) = Coord(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewCoord(i) = Coord(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewCoord(i) = Coord(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</P>
<P>End If<BR>ssetObj.SelectByPolygon acSelectionSetWindowPolygon, NewCoord<BR>ssetObj.Highlight True<BR>ssetObj.Update<BR>NumSel = ssetObj.Count<BR>Exit Sub<BR>Err1:<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item("TEST_SSET2").Delete<BR>&nbsp;&nbsp;&nbsp; Resume<BR>End Sub</P>

arden 发表于 2006-1-5 14:53:00

刚才没把付件搞上

happy336 发表于 2019-10-15 08:17:31

谢谢分享,不错
页: [1]
查看完整版本: 计算图斑面积时的岛