Python: Trying to get all family types in all families into one list, is that possible?

Just like the title, I can get all elements by category or by Family Instance or by Family Symbol, but is there a way to get all of the family types in the project. I’m also not trying to get the ones modelled as elements in the project. Basically we have a template with all families imported and my goal is to check and change the prefix of all the families, but I can’t seem to select all the family types.

There are quite a few ways of getting what you want.

This is one possible way.

2 Likes

With a python node

import clr

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

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import FamilySymbol, FilteredElementCollector


doc = DocumentManager.Instance.CurrentDBDocument

OUT = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()
3 Likes

@Mike.Buttery @pyXam Thank you both for the input, I was already getting the FamilySymbols before, but it seems like I wasn’t as clear in my question. I want to rename all family types and things like this Segmented Bend / Tee is obviously renamable, but it doesn’t show up when I try both your methods. I’m guessing this will turn out to be more of an educational instruction on why I can’t grab these family types while I’m able to grab other family types, than it being a direct solution to include these types as well:

If you want to get all ElementType elements that can be renamed you can use this code

import clr
from System import Enum

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

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import (
    BuiltInCategory,
    BuiltInParameter,
    FilteredElementCollector,
    ParameterUtils,
)


def flatten(x):
    out = []
    for i in x:
        out.extend(i)
    return out


def get_elementtype_name(et, typeid):
    fn, tn = et.FamilyName, et.GetParameter(typeid).AsValueString()
    if fn:
        if tn:
            return f"{fn}: {tn}"
        return fn
    return tn


def fec(bic):
    return (
        FilteredElementCollector(doc)
        .OfCategory(bic)
        .WhereElementIsElementType()
        .ToElements()
    )


doc = DocumentManager.Instance.CurrentDBDocument

typeid = ParameterUtils.GetParameterTypeId(BuiltInParameter.SYMBOL_NAME_PARAM)

bics = Enum.GetValues(BuiltInCategory)

elem_types = flatten(filter(None, [fec(bic) for bic in bics]))

# remove duplicates with dict comprehension
elem_types = {et.Id.ToString(): et for et in elem_types}

OUT = sorted(
    [
        (get_elementtype_name(et, typeid), et)
        for et in elem_types.values()
        if et.CanBeRenamed
    ],
    key=lambda n: n[0],
)
1 Like

Going to copy paste something I said to someone the other day which sounds like exactly what you need also:

Whilst this is definitely possible with Dynamo, I would recommend you check out the free plugin by DiRoots called “Family Reviser” (found here ).

I have used it a lot to find & replace family names across an entire library of families with the dropdown option for system families also. You can also save and export them from here, it really is a great tool.

1 Like