Python to get specific family?

Is there an oneline Python code that can filter a specific family?.
I made this work but thinking there must be a simpler way.

bip = BuiltInParameter.ALL_MODEL_TYPE_NAME
rule0 = FilterStringRule(ParameterValueProvider(ElementId(bip)), FilterStringContains(), "AAL A1 Titleblock_no notes", False);

bip1 = BuiltInParameter.ALL_MODEL_FAMILY_NAME
rule1 = FilterStringRule(ParameterValueProvider(ElementId(bip1)), FilterStringEquals(), "TitleBlock A1 Assembly", False);

filter = ElementParameterFilter([rule0,rule1]);
titleblockTypes = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_TitleBlocks).WhereElementIsElementType().WherePasses(filter).ToElements()

Sure, just replace “m_desk” with your desired family name and replace “1525 x 762mm” with your desired type. I’ve also posted some other useful stuff that I usually use in my codes.

# Get All Family Types Of Specific Family
allfamtypes = [x for x in FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements() if "m_desk".lower() == x.FamilyName.lower()]

# Get Specific Family Type Of Specific Family
specificfamtype = [x for x in FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements() if "m_desk".lower() == x.FamilyName.lower() and x.GetParameters("Type Name")[0].AsString().lower() == "1525 x 762mm".lower()]

# Get Specific Family
specificfamily = [x for x in FilteredElementCollector(doc).OfClass(Family).ToElements() if "m_desk".lower() == x.Name.lower()]

Full Code

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

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

doc = DocumentManager.Instance.CurrentDBDocument

# Get All Family Types Of Specific Family
allfamtypes = [x for x in FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements() if "m_desk".lower() == x.FamilyName.lower()]

# Get Specific Family Type Of Specific Family
specificfamtype = [x for x in FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements() if "m_desk".lower() == x.FamilyName.lower() and x.GetParameters("Type Name")[0].AsString().lower() == "1525 x 762mm".lower()]

# Get Specific Family
specificfamily = [x for x in FilteredElementCollector(doc).OfClass(Family).ToElements() if "m_desk".lower() == x.Name.lower().lower()]

OUT = allfamtypes,specificfamtype,specificfamily

Hello
for information, it is not because a code is shorter that it will be more efficient
some examples to compare execution times






9 Likes

Was this one graph or separate ones? Revit being -in process can really skew these efforts due to the nature of BIM.

one graph

1 Like

PVPs are the best. They are cumbersome to write, but many times I have accelerated codes by using them, and honestly it also makes them more stable and potentially effective in multiple languages.

1 Like