FilteredElementCollector.UnionWith() not working


#1

FilteredElementCollectors 4 and 5 as per code below each return the correct set, but for some reason I cant seem to merge them using the “.UnionWith()” method. Any ideas?

`    bip4 = BuiltInParameter.ALL_MODEL_FAMILY_NAME

provider4 = ParameterValueProvider(ElementId(bip4))
evaluator4 = FilterStringEquals();
rule4 = FilterStringRule(provider4, evaluator4, “Drainage Riser Number”, True);
filter4 = ElementParameterFilter(rule4);
collector4 = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericAnnotation).WhereElementIsNotElementType().OfClass(FamilyInstance).WherePasses(filter4)

bip5 = BuiltInParameter.ALL_MODEL_FAMILY_NAME
provider5 = ParameterValueProvider(ElementId(bip5))
evaluator5 = FilterStringEquals();
rule5 = FilterStringRule(provider5, evaluator5, “Fire Riser Number”, True);
filter5 = ElementParameterFilter(rule5);
collector5 = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericAnnotation).WhereElementIsNotElementType().OfClass(FamilyInstance).WherePasses(filter5).UnionWith(collector4)

genericAnnotations = collector5.ToElements()

TransactionManager.Instance.EnsureInTransaction(doc)
TransactionManager.Instance.TransactionTaskDone()

OUT = genericAnnotations`


#2

While the union method does not work, creating a logical filter does:

bip = BuiltInParameter.ALL_MODEL_FAMILY_NAME
provider = ParameterValueProvider(ElementId(bip))
evaluator = FilterStringEquals();
rule = FilterStringRule(provider, evaluator, xFamilyName, True);
filter = ElementParameterFilter(rule); #True inverts the filter
#xFamilyTypes = FilteredElementCollector(doc).OfCategory(xBuiltInCategories[i]).WhereElementIsElementType().WherePasses(filter).ToElements()#.OfClass(FamilyInstance)

bip1 = BuiltInParameter.SYMBOL_NAME_PARAM
provider1 = ParameterValueProvider(ElementId(bip1))
evaluator1 = FilterStringEquals();
rule1 = FilterStringRule(provider1, evaluator1, xTypeNames[i], True);
filter1 = ElementParameterFilter(rule1);

logicalAndFilter = LogicalAndFilter(filter, filter1)

xFamilyTypes = FilteredElementCollector(doc).OfCategory(xBuiltInCategories[i]).WhereElementIsElementType().WherePasses(logicalAndFilter).ToElements()