fengxue007 发表于 2008-6-17 14:56:00

如何创建选择集,选择闭合的多段线?

rt,谢谢!

robbin840311 发表于 2008-6-18 09:59:00

<p>LZ,代码如下,请试运行,运行过程ClosedLwpSelSet</p><p>Option Explicit</p><p>'创建选择闭合多段线的选择集<br/>Public Sub ClosedLwpSelSet()<br/>&nbsp; Dim pClosedLwpSelSet As AcadSelectionSet<br/>&nbsp; Set pClosedLwpSelSet = CreateSelectionSet<br/>&nbsp; <br/>&nbsp; Dim n As Integer<br/>&nbsp; n = ThisDrawing.ModelSpace.Count - 1<br/>&nbsp; Dim m As Integer&nbsp;&nbsp; '记录闭合多段线<br/>&nbsp; m = 0</p><p>&nbsp; Dim pLwpObj() As AcadLWPolyline<br/>&nbsp; '得到图形中有多少个闭合的多段线<br/>&nbsp; Dim I As Integer<br/>&nbsp; For I = 0 To n<br/>&nbsp;&nbsp;&nbsp; If TypeOf ThisDrawing.ModelSpace.Item(I) Is AcadLWPolyline Then&nbsp; '是多段线<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ThisDrawing.ModelSpace.Item(I).Closed = True Then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '多段线是闭合的<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve pLwpObj(m) As AcadLWPolyline&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '重新定义数组<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set pLwpObj(m) = ThisDrawing.ModelSpace.Item(I)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m = m + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp; Next I</p><p>&nbsp; pClosedLwpSelSet.AddItems pLwpObj&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '生成闭合多段线的选择集<br/>&nbsp; <br/>End Sub</p><p>'创建选择集的函数<br/>Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet</p><p>&nbsp;&nbsp;&nbsp; Dim ss As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; Set ss = ThisDrawing.SelectionSets(ssName)<br/>&nbsp;&nbsp;&nbsp; If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)<br/>&nbsp;&nbsp;&nbsp; ss.Clear<br/>&nbsp;&nbsp;&nbsp; Set CreateSelectionSet = ss</p><p>End Function<br/></p>

fengxue007 发表于 2008-6-18 23:52:00

<p>谢谢你了!</p><p>我在版上看到有人说用70组码=1选择封闭多段线,我已经用这种方法选择了!</p><p>代码如下:</p><p>&nbsp;&nbsp;&nbsp; Dim sset As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; Dim fType(0 To 1) As Integer<br/>&nbsp;&nbsp;&nbsp; Dim fData(0 To 1) As Variant<br/>&nbsp;&nbsp;&nbsp; fType(0) = 0: fData(0) = "*Polyline"<br/>&nbsp;&nbsp;&nbsp; fType(2) = 70: fData(2) = 1<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; If Not IsNull(ThisDrawing.SelectionSets.Item("pl")) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Item("pl")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sset.Delete<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Add("pl")<br/>&nbsp;&nbsp;&nbsp; sset.SelectOnScreen fType, fData<br/></p>

robbin840311 发表于 2008-6-19 08:21:00

呵呵,那这种方法就是最好的方法啦,学习了!谢谢分享!
页: [1]
查看完整版本: 如何创建选择集,选择闭合的多段线?