Filter Family and Category at the same time using RevitAPI


I am querying all loaded families of a specific category (ex. families of pipe fittings) but I cannot do it in FilteredElementCollector of RevitDB API. I am coding in python.

I tried the code below but I got all the families in Revit with different category:

I also tried the code below but got all the family types for a specific category.

But when I tried the code below, somehow I get an empty list.

Is there any way to do querying all the loaded families of a specific category using FilteredElementCollector?

Thank you in advance.

Do you mean like that? You don’t need OfClass if you want to look up all elements.


Hi @Deniz_Maral

That will query all the elements of the catevory, not the family.


Hi @blsalvio

You could try the other way round first by BuiltInCategory and then ByClass:

1 Like

Hi @Kulkul

Based from the picture you attached, you are querying family types. Is there a way to query the base family? I can query the family of categories now but not of a specific category. I have to add a for loop to query families of a specific category. If possible, I want to use one line only because I am doing 70k pipes and 70k fittings. A lot of for loop may slow my script.


Here is the one line code :slight_smile:

import clr

import RevitServices
from RevitServices.Persistence import DocumentManager
doc =  DocumentManager.Instance.CurrentDBDocument

from Autodesk.Revit.DB import *

OUT = [f.Family for f in FilteredElementCollector(doc).OfClass(FamilySymbol).OfCategory(BuiltInCategory.OST_Doors).ToElements()]


Thanks, same with my method, I guess there is no other way. The master has already said the best way :joy:

Another way

import clr
import sys
import System
from System.Collections.Generic import List
from Autodesk.DesignScript.Geometry import *

#import Revit API
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

filter = System.Predicate[System.Object](lambda x : x.FamilyCategory.Id == ElementId(BuiltInCategory.OST_Doors))
fec = List[DB.Element](FilteredElementCollector(doc).OfClass(Family).ToElements()).FindAll(filter)

OUT = fec

This is the solution Ive been looking for. Tested it in c#, it gives me a faster way of querying families.


@blsalvio And here is another method with one line code slightly different than @c.poupin :slight_smile:


hi @Kulkul

Thank you very much. Your code differs with @c.poupin a little bit but when I convert it to c#, it is exactly the same. I am just doing scriptlets in python and if successful, I implement it in c#. Right now, my job is to optimize code and make the existing scripts and nodes faster and efficient to handle hundreds of thousands of elements in one model.

Again, I cannot thank you enough for the suggestions you have given me.