Get all elements of multiple wall types

Hello!

I filtered out a couple of wall types and now I would like to select all the elements of this wall types but cant seem to find the solution for it in python. I know there are Dynamo nodes for it but I am trying to take a deeper dive in the Revit API, but yeah it is confusing. There are probably multiple ways of doing this, but am I supposed to construct a filter of some sorts and than use the FilteredElementCollector method? Can anybody help me out?

This is what I got so far

types =

category = ListBuiltInCategory
category.Add(BuiltInCategory.OST_Walls)
filter = ElementMulticategoryFilter(category)
collector = FilteredElementCollector(doc).WherePasses(filter).WhereElementIsElementType().ToElements()

TransactionManager.Instance.EnsureInTransaction(doc)

for item in collector:
if item.GetParameters(“LV_Beschreibung”)[0].AsString() == “Einfachständerwand”:
types.append(item)

TransactionManager.Instance.TransactionTaskDone()

OUT = types

image

Hi @borna.molnar-erhatic,

You can set up the collector with a filter element, but it’s not a necessity. You can simply do:

collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType().ToElements()

The transaction is not necessary either in your case, as you aren’t making any changes to the document.

So from the collector, you can simply go:

for item in collector:
    if item.LookupParameter('LV_Beschreibung').AsString() == 'Einfachständerwand':
        types.append(item)
    else:
        pass

OUT = items

See if it works. Otherwise, perhaps you could upload a small sample rvt with the walls for further testing :slight_smile:

Hi,

seeing the previous reply I think I might have misunderstood you - but I thought that you already have the wall types and you want to find wall elements that have those specific types assigned.
If that’s the case you can do it like this:

# Enable Python support and load DesignScript library
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument


# The inputs to this node will be stored as a list in the IN variables.
wall_types = UnwrapElement(IN[0])
type_ids = [a.Id for a in wall_types]
output = []

collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()

for wall in collector:
	if wall.WallType.Id in type_ids:
		output.append(wall)

# Assign your output to the OUT variable.
OUT = output
2 Likes

That is it! Thank you very much

1 Like

Ah sorry! I was a bit quick to read the post and missed a crucial part of the first line :laughing: :laughing: