Get all Walls with a given WallType

Get all Walls with a given WallType

Ryan_Daley
Participant Participant
1,794 Views
3 Replies
Message 1 of 4

Get all Walls with a given WallType

Ryan_Daley
Participant
Participant

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)));

 

0 Likes
Accepted solutions (1)
1,795 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni
Accepted 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:

    

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/CmdCollectorPer...

   

        /// <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!

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 4

Ryan_Daley
Participant
Participant

And what about the wallType.GetDependencyElements(ElementFilter filter) method?

Is that still less efficient than what you posted?

0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni

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.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open