I have a known WallType, and I want to find all the Wall(s) that use that WallType. What is the best way to do this. I can do this, but it seems inefficient:
WallType wallType = wall.WallType;
FilteredElementCollector walls = new FilteredElementCollector(doc).OfClass(typeof(Wall));
foreach(Wall w in walls)
{
if(w.WallType.Id == wallType.Id)
{
//do something here
}
}
EDIT:
It seems like .GetDependentElements() is working. I would guess this is more efficient than the alternative:
IList<ElementId> dependentWalls = wallType.GetDependentElements(new ElementClassFilter(typeof(Wall)));
Solved! Go to Solution.
Solved by jeremy_tammik. Go to Solution.
Your approach is not too bad. It uses .NET post-processing to query the WallType property of every wall.
If you can move that query into a Revit filtered element collector filer, it will speed up by a factor of two or so for every wall in your project due to not having to marshal data or every single wall in your project from native Revit memory out to the .NET environment. Also, if the wall type filter fails for a specific wall instance, it does not have to transfer any data at all for it, so then you save almost 100% of your processing time.
So, how to get that query into a filter?
Well, search for a non-.NET way to check for the wall type. As it happens, the wall type is stored in a parameter on the wall object. You can see that using RevitLookup. Plus, you can filter for parameter values. So, that's the way to go.
I suggest you take a look at The Building Coder samples GetAllElementsUsingType method:
/// <summary>
/// Return the all elements that
/// use the given ElementType.
/// </summary>
private static FilteredElementCollector
GetAllElementsUsingType(
Document doc,
ElementType et)
{
// Built-in parameter storing the type element id:
var bip
= BuiltInParameter.ELEM_TYPE_PARAM;
var provider
= new ParameterValueProvider(
new ElementId(bip));
FilterNumericRuleEvaluator evaluator
= new FilterNumericEquals();
FilterRule rule = new FilterElementIdRule(
provider, evaluator, et.Id);
var filter
= new ElementParameterFilter(rule);
var collector
= new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.WherePasses(filter);
return collector;
}
#endregion // GetAllElementsUsingType
Please benchmark your current solution, compare with the parameter filter approach, and let us know the results.
Thank you!
And what about the wallType.GetDependencyElements(ElementFilter filter) method?
Is that still less efficient than what you posted?
Very interesting question. Nobody in the world except you can answer it. Please benchmark and let us know the result. It will almost certainly depend on your model and other circumstances. I would guess the parameter filter and the DependencyElements approaches will have comparable performance, but I really don't know, and I suspect nobody else does either... yet.
Can't find what you're looking for? Ask the community or share your knowledge.