求助:如何删除选择集外的所有对象?
<p>求助:如何删除选择集外的所有对象,或者反向选择?</p> 创建两个选择集,选择集1选择全部,选择集2为你当前的选择集,选择集1和选择集2的差集就是选择集外的所有对象或反向选择 <p>自定义vba函数:选择集的补集。</p><p>'示例<br/>Sub Example_ssOpposite()<br/> Dim ss As AcadSelectionSet<br/> Set ss = ThisDrawing.PickfirstSelectionSet<br/> Set ss = ssOpposite(ss)<br/> ss.Erase<br/> ss.Delete<br/> ThisDrawing.Regen True<br/>End Sub<br/>'单个选择集的补集<br/>Public Function ssOpposite(subSet As AcadSelectionSet) As AcadSelectionSet<br/> Dim Ent As AcadEntity<br/> Dim objArray() As AcadEntity<br/> Dim j As Long<br/> j = -1<br/> For Each Ent In ThisDrawing.ModelSpace<br/> If Not EntIsInSSet(Ent, subSet) Then<br/> j = j + 1<br/> ReDim Preserve objArray(j)<br/> Set objArray(j) = Ent<br/> End If<br/> Next<br/> subSet.Clear<br/> subSet.AddItems objArray<br/> Set ssOpposite = subSet<br/>End Function<br/>'判断某图元是否存在于某选择集<br/>Private Function EntIsInSSet(Ent As AcadEntity, SSet As AcadSelectionSet) As Boolean<br/> Dim i As Long<br/> For i = 0 To SSet.Count - 1<br/> If SSet(i).Handle = Ent.Handle Then<br/> EntIsInSSet = True<br/> Exit Function<br/> End If<br/> Next<br/> EntIsInSSet = False<br/>End Function</p><p></p> 多谢二位老兄!
页:
[1]