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:

#Boilerplate Code

family_instance = UnwrapElement(IN[0])
family_type_id = family_instance.GetTypeId()
family_type = doc.GetElement(family_type_id)
family = family_type.Family
OUT = family_instance, family_type, family

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:

#Boilerplate Code

family = UnwrapElement(IN[0])
family_type_ids = family.GetFamilySymbolIds()
family_types = [doc.GetElement(id) for id in family_type_ids]
OUT = family_types

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.

#Boilerplate Code

family = UnwrapElement(IN[0])
family_type_ids = family.GetFamilySymbolIds()

family_instances = []

for family_type_id in family_type_ids:
	family_instance_filter = FamilyInstanceFilter(doc, family_type_id)
	elements = FilteredElementCollector(doc).WherePasses(family_instance_filter).ToElements()
	family_instances.append(elements)

OUT = family_instances

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 updated