Mar 16, 2024

Get all Nested Families inside your family with Revit API

What if you want to look inside of a family and see inside any of those families and so on... Well you would need to create recursive function

How to Get Nested families ?

I've been asked on how to create a recursive function to look inside of nested families and their nested families.

1️⃣ Get all Families

First of all let's get all families in Revit before we look inside of them, by opening them as a Family Document.

all_families = FilteredElementCollector(doc).OfClass(Family).ToElements

#1. Get Your Element
win_fam = doc.GetElement(ElementId(361048))

# Recursive Function
def print_nested_families(doc, family_element, suf = ""):
    if family_element and family_element.IsEditable:
        print(suf + family_element.Name)
        suf += '--'           
        fam_doc           = doc.EditFamily(family_element)
        families          = FilteredElementCollector(fam_doc).OfClass(Family).ToElements()
        editable_families = [f for f in families if f.IsEditable]
        # Print the names of the editable families
        for f in editable_families:
            print_nested_families(fam_doc, f, suf)

# Example usage
print_nested_families(doc, win_fam)

Want to Learn More?

🔥 Amazing Revit API Resources!

Join Revit API

Newsletter Today!

Join Us!

which is already read by 4000+ people!

Get short Revit API Lessons and Tips directly in your mail!