4.13 Family Acrobatics
Family -> FamilyType -> FamilyInstance -> FamilyType -> Family
Going Between FamilyInstance, FamilyType and Family
The Revit application uses a hard-coded hierarchy between Family, FamilyType and FamilyInstance objects. A family may contain many family types, a family type may be placed many times.
When working with scripts, I often need to go between accessing a FamilyInstance’s parameters, its Type Parameters and sometimes Family. The Revit API provides methods to move between these in a straightforward manner.

Moving Upstream from FamilyInstance -> FamilyType -> Family

Each FamilyInstance will derive from a single FamilyType. Likewise, each FamilyType will be defined by a single Family in the document. We can move upstream from FamilyInstance to Family like so:
1
#Boilerplate Code
2
3
family_instance = UnwrapElement(IN[0])
4
family_type_id = family_instance.GetTypeId()
5
family_type = doc.GetElement(family_type_id)
6
family = family_type.Family
7
OUT = family_instance, family_type, family
Copied!

Moving Downstream from Family -> FamilyTypes -> FamilyInstances

This way is more complicated; there is a many-to-one relationship between a Family object and its many potential FamilyType objects. Likewise, there could be many placed FamilyInstances of any FamilyType. To get all family_types of a family, we could use:
1
#Boilerplate Code
2
3
family = UnwrapElement(IN[0])
4
family_type_ids = family.GetFamilySymbolIds()
5
family_types = [doc.GetElement(id) for id in family_type_ids]
6
OUT = family_types
Copied!
Finding all FamilyInstance objects of a given Type is less straightforward - we'll first need to create a FamilyInstanceFilter using the Id of the required FamilyType.
1
#Boilerplate Code
2
3
family = UnwrapElement(IN[0])
4
family_type_ids = family.GetFamilySymbolIds()
5
6
family_instances = []
7
8
for family_type_id in family_type_ids:
9
family_instance_filter = FamilyInstanceFilter(doc, family_type_id)
10
elements = FilteredElementCollector(doc).WherePasses(family_instance_filter).ToElements()
11
family_instances.append(elements)
12
13
OUT = family_instances
Copied!
On Line 9 above, we create the FamilyInstanceFilter, which takes our document and the FamilyType's Id as arguments. We can then pass this in as a modifier to the FilteredElementCollector on Line 10.
Last modified 1yr ago
Copy link