既存の選択セットを参照するには、既知の場合は、その名前を使用します。
次の例は、"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
' Find each selection set in the drawing
i = 0
For Each selset In selsetCollection
MsgBox "Selection set " & CStr(i) & " is: " & selset.Name
' Now find each object in the selection set, and say what it is
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