Dynamo Python Primer
  • Take Dynamo Further πŸš€
  • 1 Hello Python 🐍
    • 1.1 Why Should I Learn to Code?
    • 1.2 Python Introduction
    • 1.3 What is IronPython?
  • 2 Seeing The Bigger Picture πŸ”­
    • 2.1 Context Matters
    • 2.2 What is an API?
    • 2.3 The .NET Framework
    • 2.4 Object-Oriented Programming
  • 3 Getting Started πŸ›΄
    • 3.1 Dynamo's Python Node
    • 3.2 Boilerplate Setup Code
    • 3.3 Basics: Input and Output
    • 3.4 Common Errors
  • 4 Revit-Specific Topics 🏑
    • 4.1 Introduction to Revit's API
    • 4.2 How to Read Revit's API Documentation
    • 4.3 Doc, UIDoc, App, UIApp
    • 4.4 Unwrapping Revit Elements
    • 4.5 The FilteredElementCollector
    • 4.6 Geometry Conversion Methods
    • 4.7 Working With Parameters
      • Family Parameters
      • Global Parameters
      • Project Information Parameters
      • Group Parameters
      • Built-In Parameters
    • 4.8 Working With Transactions
    • 4.9 Opening & Closing External Files
    • 4.10 Prompting UI Selection
    • 4.11 Working With Units
    • 4.12 Built-In Categories
    • 4.13 Family Acrobatics
    • 4.14 Feedback: TaskDialogs
  • 5 Glossary πŸ“š
  • About This Primer πŸ‘‹
Powered by GitBook
On this page

Was this helpful?

  1. 4 Revit-Specific Topics 🏑

4.13 Family Acrobatics

Family -> FamilyType -> FamilyInstance -> FamilyType -> Family

Previous4.12 Built-In CategoriesNext4.14 Feedback: TaskDialogs

Last updated 5 years ago

Was this helpful?

Going Between FamilyInstance, FamilyType and Family

The Revit application uses a hard-coded hierarchy between , and 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
#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

Finding all FamilyInstance objects of a given Type is less straightforward - we'll first need to create a using the Id of the required FamilyType.

On Line 9 above, we create the FamilyInstanceFilter, which takes our and the FamilyType's Id as arguments. We can then pass this in as a modifier to the on Line 10.

Family
FamilyType
FamilyInstance
FamilyInstanceFilter
document
FilteredElementCollector