I have this function that runs a few filters in loops that I would like to see if they can all be combined into one call to doc.elements(filter,elementarray). First I get a list of all family symbols that have our shared parameter "UsageID". Then I cycle through all the found symbols and look for any family instance objects using one of those family symbols. To put it in straight words, I want ALL family instance type objects that have a family symbol whose parameter "UsageID" = strUsageID. Can it be done in one compound filter? Thank you in advance if you have ANY ideas or improvements.
Public Function GetFamilyInstancesByUsageID(ByVal strUsageID As String) As ElementArray
Dim eaFamSym As New ElementArray
Dim eaFamInst As New ElementArray
'run filter on family instances that are framing
Dim cf As Creation.Filter = rApp.Create.Filter
Dim fFamInst As Filter = cf.NewTypeFilter(GetType(Elements.FamilyInstance))
'run filter on family symbols that have usageID paramter of strUsageID
Dim fUsage As Filter = cf.NewParameterFilter("UsageId", Enums.CriteriaFilterType.Equal, strUsageID)
Dim fFamSym As Filter = cf.NewTypeFilter(GetType(Symbols.FamilySymbol))
Dim fFSandU As Filter = cf.NewLogicAndFilter(fUsage, fFamSym)
Dim n As Integer = doc.Elements(fFSandU, eaFamSym)
For Each fs As Symbols.FamilySymbol In eaFamSym 'cycle through all family symbols used for as a strUsageID
Dim fFamSymName As Filter = cf.NewSymbolFilter(fs.Name)
Dim fFinal As Filter = cf.NewLogicAndFilter(fFamInst, fFamSymName)
n = doc.Elements(fFinal, eaFamInst)
Next
Return eaFamInst
End Function