VBA Selection Set optimization

For some reason, I have never really understood the whole filtered selection sets – it was actually some syntax issues. If you don’t pass the correct types into SS.Select … things go very wrong. Here is some code that works.  Note that ClearSelectionSet merely pre-deletes the named selection set. A useful links to shed some light on dxf codes is here. Here is the main article that solved my dilemna, I copied and pasted it and it worked – why didn’t mine? Not sure – need to get on with life. 🙂 .

[vb]

Function getXRefsAlternate() As AcadSelectionSet
Dim blkDef As AcadBlock, xref As AcadExternalReference
Dim fType(1) As Integer, fData(1)
Dim ss As AcadSelectionSet

Dim ObjsetRef As AcadSelectionSet

If ObjsetRef Is Nothing Then
ClearSelectionSet "XrefObjects" ‘switched from generic to aco
Set ObjsetRef = thisDrawing.SelectionSets.Add("XrefObjects")
End If

ClearSelectionSet "ss"
Set ss = aco.thisDrawing.SelectionSets.Add("ss")

fType(0) = 0: fData(0) = "INSERT"
fType(1) = 2

For Each blkDef In aco.thisDrawing.Blocks
If blkDef.IsXRef Then
fData(1) = blkDef.name
ss.Select acSelectionSetAll, , , fType, fData
If ss.count > 0 Then
For Each xref In ss
‘Debug.Print "Santa"
Dim ao(0) As AcadEntity
Set ao(0) = xref
ObjsetRef.AddItems ao
Set ao(0) = Nothing
Next
End If
End If
Next

Set getXRefsAlternate = ObjsetRef
End Function

[/vb]