自定义vba函数:选择集的补集。 '示例 Sub Example_ssOpposite() Dim ss As AcadSelectionSet Set ss = ThisDrawing.PickfirstSelectionSet Set ss = ssOpposite(ss) ss.Erase ss.Delete ThisDrawing.Regen True End Sub '单个选择集的补集 Public Function ssOpposite(subSet As AcadSelectionSet) As AcadSelectionSet Dim Ent As AcadEntity Dim objArray() As AcadEntity Dim j As Long j = -1 For Each Ent In ThisDrawing.ModelSpace If Not EntIsInSSet(Ent, subSet) Then j = j + 1 ReDim Preserve objArray(j) Set objArray(j) = Ent End If Next subSet.Clear subSet.AddItems objArray Set ssOpposite = subSet End Function '判断某图元是否存在于某选择集 Private Function EntIsInSSet(Ent As AcadEntity, SSet As AcadSelectionSet) As Boolean Dim i As Long For i = 0 To SSet.Count - 1 If SSet(i).Handle = Ent.Handle Then EntIsInSSet = True Exit Function End If Next EntIsInSSet = False End Function |