I have use.
Is it Show Filter
String Section_Name = "XXXXXXX";
IEnumerable<Element> elems = collect.OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>()
.Where(x => x.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString() == Section_Name);
Any alternate method using LINQ without BuiltInParameter?
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Please check your spelling before posting!
I assume you mean to ask:
Question: Is this filter a slow filter?
Answer: No, it is not. It is even slower than a slow filter.
This example retrieves the element data from Revit to the .NET add-in memory space, and the uses .NET and LINQ to post-process it.
http://thebuildingcoder.typepad.com/blog/2015/12/quick-slow-and-linq-element-filtering.html
You could convert it to a fast filter by implementing a parameter filter to compare the family name:
Cheers,
Jeremy
I cleaned up The Building Coder sample code demonstrating retrieving named family symbols using either LINQ or a parameter filter for you:
#region Retrieve named family symbols using either LINQ or a parameter filter static FilteredElementCollector GetStructuralColumnSymbolCollector( Document doc ) { return new FilteredElementCollector( doc ) .OfCategory( BuiltInCategory.OST_StructuralColumns ) .OfClass( typeof( FamilySymbol ) ); } static IEnumerable<Element> Linq( Document doc, string familySymbolName ) { return GetStructuralColumnSymbolCollector( doc ) .Where( x => x.Name == familySymbolName ); } static IEnumerable<Element> Linq2( Document doc, string familySymbolName ) { return GetStructuralColumnSymbolCollector( doc ) .Where( x => x.get_Parameter( BuiltInParameter.SYMBOL_NAME_PARAM ) .AsString() == familySymbolName ); } private static IEnumerable<Element> FilterRule( Document doc, string familySymbolName ) { return GetStructuralColumnSymbolCollector( doc ) .WherePasses( new ElementParameterFilter( new FilterStringRule( new ParameterValueProvider( new ElementId( BuiltInParameter.SYMBOL_NAME_PARAM ) ), new FilterStringEquals(), familySymbolName, true ) ) ); } private static IEnumerable<Element> Factory( Document doc, string familySymbolName ) { return GetStructuralColumnSymbolCollector( doc ) .WherePasses( new ElementParameterFilter( ParameterFilterRuleFactory.CreateEqualsRule( new ElementId( BuiltInParameter.SYMBOL_NAME_PARAM ), familySymbolName, true ) ) ); } #endregion // Retrieve named family symbols using either LINQ or a parameter filter
I hope this clarifies.
Cheers,
Jeremy
Hi,
Please verify below code
//FilteredElementCollector collect = new FilteredElementCollector(doc); //IEnumerable<Element> elems = collect.OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>() // .Where(x => x.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString() == "Modular Gang Box"); FilteredElementCollector collect = new FilteredElementCollector(doc,uidoc.ActiveView.Id); IEnumerable<Element> elems = collect.OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>() .Where(x => x.Symbol.Family.Name.Equals("Modular Gang Box"));
I ask you sorry if I made mistake.
Regards,
Sudhan.
If this works for you and does what you need, then all is fine.
However, this is not a fast filter, nor is it a slow filter.
It is slower still.
The Where clause is a LINQ construct, in .NET, not a Revit filter at all.
In order for it to work, the Revit API has to transport all the element data out of the Revit memory space to .NET, where it is being post-processed.
This transport process is called marshalling and costs more time than all Revit filters, regardless whether they are fast or slow.
I cleaned up and published my previous answer on The Building Coder, in case that helps:
https://thebuildingcoder.typepad.com/blog/2019/04/slow-slower-still-and-faster-filtering.html
Best regards,
Jeremy