cqy 发表于 2009-1-9 13:14:00

求助:如何删除选择集外的所有对象?

<p>求助:如何删除选择集外的所有对象,或者反向选择?</p>

wylong 发表于 2009-1-9 17:43:00

创建两个选择集,选择集1选择全部,选择集2为你当前的选择集,选择集1和选择集2的差集就是选择集外的所有对象或反向选择

dianbotang 发表于 2009-4-4 20:44:00

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

cqy 发表于 2009-4-6 21:49:00

多谢二位老兄!
页: [1]
查看完整版本: 求助:如何删除选择集外的所有对象?