# Revit API - FilteredElementCollector - Get Family by BuiltInCategory & Family Name

**URL:** <https://forum.dynamobim.com/t/revit-api-filteredelementcollector-get-family-by-builtincategory-family-name/59719>\
**Category:** Developers\
**Tags:** revit\
**Created:** [January 26, 2021, 3:20am UTC](https://forum.dynamobim.com/t/revit-api-filteredelementcollector-get-family-by-builtincategory-family-name/59719 "2021-01-26T03:20:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Fleming](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/matt_fleming/32/8868_2.png) [@Matt\_Fleming](https://forum.dynamobim.com/u/Matt_Fleming)\
**Post date:** [January 26, 2021, 3:20am UTC](https://forum.dynamobim.com/t/revit-api-filteredelementcollector-get-family-by-builtincategory-family-name/59719/1 "2021-01-26T03:20:48Z")

</div>

This should be pretty simple in Revit 2020 API but I can’t seem to get it.  
I’m trying Select a Detail Component Family in the Project to be able to place it in a view.

- Family Category = Detail Component
- Family Name = myFamilyName
- FamilySymbol Type = myFamilySymbolTypeName

I’m stuck on the filtering first part. I can get all the Family Names in the project, but I can’t seem to filter them out by BuiltInCategory to only shown loaded Detail Components?

```
FilteredElementCollector collector2 = new FilteredElementCollector(doc);
            ICollection<Element> ele2 = collector2
                .OfClass(typeof(Family))
                .OfCategory(BuiltInCategory.OST_DetailComponents) //This is where its not working. If I comment this out, I get all Familes in Project
                .ToElements();
            StringBuilder sb2 = new StringBuilder();
            foreach (Element el2 in ele2)
            {
                sb2.AppendLine(el2.Name);
            }
            TaskDialog.Show("reavit", sb2.ToString());
```

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [January 26, 2021, 8:13am UTC](https://forum.dynamobim.com/t/revit-api-filteredelementcollector-get-family-by-builtincategory-family-name/59719/2 "2021-01-26T08:13:22Z")

</div>

It’s Python instead of C, but this should help:

```
adds the common language runtime to the Iron Python environment
import clr
#adds the Revit Services DLL to the CLR
clr.AddReference("RevitServices")
#adds the Revit Services namespace to the Iron Python environment
import RevitServices
#adds the document manager to the Iron Python environment
from RevitServices.Persistence import DocumentManager
#adds the Revit API to the CLR
clr.AddReference("RevitAPI")
#adds the FilterElementCollector, BuiltInCategory, and FamilySymbol classes to the Iron Python environment
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, FamilySymbol
#sets the doc variable to the current Revit document
doc = DocumentManager.Instance.CurrentDBDocument
#constructs a new filtered element collector, ensuring we're only getting detail components; of the class family symbol; and returning those as elements
builtInCollector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_DetailComponents).OfClass(FamilySymbol).WhereElementIsElementType().ToElements()
#note that if you omit the '.OfClass(FamilySymbol)' section you'll return the filled region types as well
#sends the results of the builtInCollector to the Dynamo environment
OUT = builtInCollector

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/c/aceeb46968a68038cd6bd04bf8b8a690d520622a.jpeg)

---

<div class="post-metadata">

**Author:** ![Matt\_Fleming](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/matt_fleming/32/8868_2.png) [@Matt\_Fleming](https://forum.dynamobim.com/u/Matt_Fleming)\
**Post date:** [January 26, 2021, 9:08pm UTC](https://forum.dynamobim.com/t/revit-api-filteredelementcollector-get-family-by-builtincategory-family-name/59719/3 "2021-01-26T21:08:51Z")

</div>

No this is where I’m stuck. It will get all detail items (filled regions etc which I don’t want) but using the

`.OfClass(FamilySymbol)`

Doesn’t work in this context.  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/e/3ea8c55d813b2e3bf55f7d5f8a0c2df1fbc7a222.png)

---

<div class="post-metadata">

**Author:** ![Matt\_Fleming](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/matt_fleming/32/8868_2.png) [@Matt\_Fleming](https://forum.dynamobim.com/u/Matt_Fleming)\
**Post date:** [January 26, 2021, 9:26pm UTC](https://forum.dynamobim.com/t/revit-api-filteredelementcollector-get-family-by-builtincategory-family-name/59719/4 "2021-01-26T21:26:20Z")

</div>

Found it. was missing the **typeof** …in .OfClass(typeof(FamilySymbol)

Final is:

```
            FilteredElementCollector collector2 = new FilteredElementCollector(doc);
            ICollection<Element> ele2 = collector2
                .OfCategory(BuiltInCategory.OST_DetailComponents)
                .OfClass(typeof(FamilySymbol))
                .WhereElementIsElementType()
                .ToElements();
```
