01 Days 08 Hrs

🥳 Late-Bird Launch Is Coming on Feb 29th!

Jan 24, 2024

How to Get Default Type in Revit API?

Learn how to get default types of your categories in Revit with a single line!

How to Get Default Types in Revit API?

Once you start using Revit API, it's likely that at some point you will need to get your default types from Revit. Many people use collectors to get all types and then grab one randomly.

But there is a much simpler approach we can use by using following methods:

Both methods come from Document Class.
Let's explore how these methods work and as usual I will give you code examples you could use!

1️⃣ How to Use GetDefaultElementTypeId

This method is used to get default element type ids of your native elements.
By native I mean elements that exist in Revit by default and can not be loaded as families.
Such as: Walls, Floors, Roofs, Levels, Grids, Regions...

Here is the syntax of how it can be used:

This method takes a single argument - ElementTypeGroup Enumeration
Since it's an enumeration - you can see all available options you can choose from.

But it would be a much simpler approach if you have Revit API autocomplete configured in your IDE. Then you write ElementTypeGroup. and you will see all possible values you can choose from.

👇 Here is a code example on how to get Default Type of Walls, Floors, FloorPlan and Regions.

#⬇️ Imports
from Autodesk.Revit.DB import *

#📦 Variables
doc   = __revit__.ActiveUIDocument.Document     #type: Document


#1️⃣ GetDefaultElementTypeId (Get Types of Native Families)
wall_type_id      = doc.GetDefaultElementTypeId(ElementTypeGroup.WallType)
floor_type_id     = doc.GetDefaultElementTypeId(ElementTypeGroup.FloorType)
view_plan_type_id = doc.GetDefaultElementTypeId(ElementTypeGroup.ViewTypeFloorPlan)
region_type_id    = doc.GetDefaultElementTypeId(ElementTypeGroup.FilledRegionType)

#👉 Convert to Elements
wall_type      = doc.GetElement(wall_type_id)
floor_type     = doc.GetElement(floor_type_id)
view_plan_type = doc.GetElement(view_plan_type_id)
region_type    = doc.GetElement(region_type_id)

#👀 Display Type Names
print(Element.Name.GetValue(wall_type))
print(Element.Name.GetValue(floor_type))
print(Element.Name.GetValue(view_plan_type))
print(Element.Name.GetValue(region_type))

💡 This method will return you ElementId, so don't forget to convert it into Elements!


2️⃣ How to Use GetDefaultFamilyTypeId

The second method is used to get default element type ids of your loadable elements.
Such as: Windows, Doors, Generic Models...

Here is the syntax of how it can be used:

This method takes a single argument - familyCategoryId.
And it's very simple to get it, we can use ElementId Constructor and provide BuiltInCategory as an argument.

Here is an Example:

door_cat_id = ElementId(BuiltInCategory.OST_Doors)

Now let's combine it with GetDefaultFamilyTypeId and write a snippet like this:

#⬇️ Imports
from Autodesk.Revit.DB import *

#📦 Variables
doc   = __revit__.ActiveUIDocument.Document     #type: Document


#2️⃣ GetDefaultFamilyTypeId (Get Types of Loaded Families)
door_type_id      = doc.GetDefaultFamilyTypeId(ElementId(BuiltInCategory.OST_Doors))
win_type_id       = doc.GetDefaultFamilyTypeId(ElementId(BuiltInCategory.OST_Windows))
gen_model_type_id = doc.GetDefaultFamilyTypeId(ElementId(BuiltInCategory.OST_GenericModel))

#👉 Convert to Elements
door_type      = doc.GetElement(door_type_id)
win_type       = doc.GetElement(win_type_id)
gen_model_type = doc.GetElement(gen_model_type_id)

#👀 Display Results
print(Element.Name.GetValue(door_type))
print(Element.Name.GetValue(win_type))
print(Element.Name.GetValue(gen_model_type))

This will get you default types of Doors, Windows and Generic Models. And the same can be applied for other categories as well!

⌨️ Happy Coding!

I hope you learnt something new, and you will use it in your own scripts.

🔥 Amazing Revit API Resources!

Join Revit API

Newsletter Today!

Join Us!

which is already read by 2200+ people!

Get short Revit API Lessons and Tips directly in your mail!