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