Get all family from a specific category

duongphong29
Enthusiast
Enthusiast

Get all family from a specific category

duongphong29
Enthusiast
Enthusiast

I'm trying to get all family from a specific category then I can use GetFamilySymbolIds() to obtain all Ids of family symbols in that family. I just simply think like this:

 

collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).OfClass(Family).ToElements()

 

In that case, I'm trying to get all family in category Structural Columns. But it gives me an empty list. 

  

Here is my code to get ids and names of family in a category:

 

collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).OfClass(Family).ToElements() #Get all family in current project


for m in collector:
    symbols_ids = list(m.GetFamilySymbolIds())
    for i in symbols_ids:
        famsymbol = doc.GetElement(i)
        symbolName = famsymbol.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
        print (symbolName + str(i))

 

Is there a way for me to do this? 

 

Thank you in advance.

 

P/s: I am using revit 2021

0 Likes
Reply
Accepted solutions (4)
5,202 Views
4 Replies
Replies (4)

architect.bim
Collaborator
Collaborator
Accepted solution

Hi! If you need to get all families just get all symbols with WhereElementIsElementType method. And then use set object to get unique family ids. That's all.

family_symbols = FilteredElementCollector(doc) \
    .OfCategory(BuiltInCategory.OST_StructuralColumns) \
    .WhereElementIsElementType()

family_ids = set(symbol.Family.Id for symbol in family_symbols)

P.S. Don't pass Families in set instead of Family Ids. It won't give you unique items.


Maxim Stepannikov | Architect, BIM Manager, Instructor

franciscopossetto
Advocate
Advocate
Accepted solution

Hey,

 

I have selected some families by Id and explored their properties using Revit Lookup. The parameter "Category" is null. The property where the Family stores their Category is called FamilyCategory. Maybe this is the reason why your collector does not return elements.

 

Alternatively, I think you could achieve the same result by doing it this way:

 

1. Get all Family Symbols of some Category:

 

 

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

 

 

2. If needed,  Filter the Family Symbols by the FamilyName:

 

 

fam_symbols_by_fam_name= list(filter(lambda x: (x.FamilyName == "Basic Wall"), collector)) 

 

 

I hope it helps.

Kind regards.

 

----------------------------------

 

EDITED:

I hadn't seen the @architect.bim  answer. Sorry for the very similar response.

Github:
https://github.com/franpossetto

duongphong29
Enthusiast
Enthusiast
Accepted solution

Thank you very much

 

Thank to you, I have found a way to reach my purpose.

 

For those who came after, this is the way to get all family type names and ids. Results shown in picture 1

 

family_symbols = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).WhereElementIsElementType() 

for symbol in family_symbols:
    family_id = symbol.Id
    family_name = symbol.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
    print(family_name + " " + str(family_id))

 

Thank you very much.

 

0 Likes

jeremy_tammik
Autodesk
Autodesk
Accepted solution

You have encountered a limitation discussed by The Building Coder twelve years ago:

 

https://thebuildingcoder.typepad.com/blog/2009/01/family-category-and-filtering.html

 

Here are some subsequent further notes on this:

 

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes