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 🏡
  2. 4.7 Working With Parameters

Family Parameters

Families are an intrinsic part of any Revit model; being able to access their parameters is a vitally important skill when coding for Revit.

Previous4.7 Working With ParametersNextGlobal Parameters

Last updated 5 years ago

Was this helpful?

Revit's family system uses a hierarchical relationship between Family Types and Family Instances. The same relationship exists in parallel in the API:

  • Placed family instances (e.g. a window or a window) are instance of Revit's class.

  • Family Types (e.g. 90 minute fire-rated door type) are instances of Revit's class.

Family Instance vs Family Type Parameters

It is worth understanding a simple fact about family parameters:

A family's instance parameters are accessed via the FamilyInstance object, whereas family type parameters are accessed via the instance's FamilyType object.

Using a few simple methods, you can move from a family instance's FamilyInstance to its associated FamilyType, and from that FamilyType to the associated Family. We can also carry out the movements in reverse, finding all Family Types of a Family, or all placed instances of a Family Type. To make things clearer, we've put this on its own page:

Seeing All Family Instance Parameters

As ever, if wanting to interact with a Revit element passed into a node, it will need to be unwrapped. See how to unwrap elements here:

Once unwrapped, you can either access a particular parameter (see section on Accessing a Specific Parameter below) or return a list of all the element's instance parameters as objects, which can be accessed via its Element.Parameters property, like so:

#Boilerplate Code
my_element = UnwrapElement(IN[0])
element_parameters = my_element.Parameters

This is akin to using the Element.Parameters node on in Dynamo. Now we have the list of Parameter objects, we can do many things. Looking at the class in ApiDocs.co, we can see there are a number of useful properties we can inspect.

Seeing All Family Type Parameters

Type Parameters need to be accessed via an element’s family type. If you have a as an input, you’ll firstly need to use an intermediate method to get the element’s object, such as GetTypeId().

family_type = doc.GetElement(family_instance.GetTypeId())

The family_type handle is now a way to access the family type object. We can then go about accessing parameters using the methods below.

Accessing a Specific Parameter

Once we've placed a handle to our FamilyInstance or FamilyType, there are a couple of different ways to access a particular parameter:

  • The Element.LookupParameter() method.

  • The Element.get_Parameter() method.

Both of these methods essentially do the same thing; they return a Parameter object which you can inspect and manipulate.

Reading A Parameter's Value

Finally, in order to read a parameter object’s value, you’ll need to convert it using one of the methods of the Parameter class, such as .AsString() or .AsDouble(). If you output the raw Parameter object, it shows as Autodesk.Revit.DB.Parameter which isn't very helpful. Use the methods above to return the value in an appropriate data type. This workflow is the equivalent of using the GetParameterValueByName node in Dynamo.

This method returns the of the element’s family type. We can then use the doc.GetElement() method to return the element’s FamilyType object. We can assign a reference to the family type, such as:

FamilyInstance
FamilyType
4.13 Family Acrobatics
Unwrapping Revit Elements
Parameter
Parameter
FamilyInstance
FamilyType
ElementId
A simple example; reading the Mark value of an element.