Q:
How do I use a selection set filter to select a block with a particular name
that is on a particular layer ?
A:
The following sample code allows you to select blocks based on this criteria:
1. selectALayer() - create a selectionset with entities on "layer1"
2. selectABlock() - create a selectionset with a block insert "testBlock"
3. selectABlockOnALayer() - create a selectionset with a block insert "testBlock" on "layer1"
Sub selectALayer()
Dim sset As AcadSelectionSet
Set sset = ThisDrawing.SelectionSets.Add("TestSet1")
Dim filterType As Variant
Dim filterData As Variant
Dim p1(0 To 2) As Double
Dim p2(0 To 2) As Double
Dim grpCode(0) As Integer
grpCode(0) = 8
filterType = grpCode
Dim grpValue(0) As Variant
grpValue(0) = "Layer1"
filterData = grpValue
sset.Select acSelectionSetAll, p1, p2, filterType, filterData
Debug.Print "Entities: " & str(sset.count)
sset.Delete
End Sub
Sub selectABlock()
Dim sset As AcadSelectionSet
Set sset = ThisDrawing.SelectionSets.Add("TestSet2")
Dim filterType As Variant
Dim filterData As Variant
Dim p1(0 To 2) As Double
Dim p2(0 To 2) As Double
Dim grpCode(0) As Integer
grpCode(0) = 2
filterType = grpCode
Dim grpValue(0) As Variant
grpValue(0) = "testBlock"
filterData = grpValue
sset.Select acSelectionSetAll, p1, p2, filterType, filterData
Debug.Print "Entities: " & str(sset.count)
sset.Delete
End Sub
Sub selectABlockOnALayer()
Dim sset As AcadSelectionSet
Set sset = ThisDrawing.SelectionSets.Add("TestSet3")
Dim filterType As Variant
Dim filterData As Variant
Dim p1(0 To 2) As Double
Dim p2(0 To 2) As Double
Dim grpCode(0 To 1) As Integer
grpCode(0) = 8
grpCode(1) = 2
filterType = grpCode
Dim grpValue(0 To 1) As Variant
grpValue(0) = "layer1"
grpValue(1) = "testBlock"
filterData = grpValue
sset.Select acSelectionSetAll, p1, p2, filterType, filterData
Debug.Print "Entities: " & str(sset.count)
sset.Delete
End Sub