显示关于选择集的信息

AutoCAD ActiveX/VBA

 
显示关于选择集的信息
 
 
 

请使用名称来引用已知的现有选择集。下例引用名为“SS10”的选择集:

Sub GetObjInSet()
  Dim selset As AcadSelectionSet
  Set selset = ThisDrawing.SelectionSets("SS10")
    
  MsgBox ("Selection set " & selset.Name & " contains " & _
    selset.Count & " items")
    
End Sub

图形中的每个选择集都是 SelectionSets 集合的成员。可以使用 For Each 语句遍历图形的 SelectionSets 集合,并收集有关每个选择集的信息。

显示图形中每个选择集的名称

以下代码显示图形中每个选择集的名称,同时列出其包含的对象的类型:

Sub ListSelectionSets()
  Dim selsetCollection As AcadSelectionSets
  Dim selset As AcadSelectionSet
  Dim ent As Object
  Dim i, j As Integer
      
  Set selsetCollection = ThisDrawing.SelectionSets
      
  ' 查找图形中的每个选择集
  i = 0
  For Each selset In selsetCollection
    MsgBox "Selection set " & CStr(i) & " is: " & selset.Name
      
    ' 现在查找选择集中的每个对象,同时显示其类型
    j = 0
    For Each ent In selset
       MsgBox "Item " & CStr(j + 1) & " in " & selset.Name _ 
         & "is: " & ent.EntityName
       j = j + 1
    Next
    i = i + 1
  Next
      
End Sub