# Revit API Python How to Get ElementId of BuiltInCategory Enumeration

**URL:** <https://forum.dynamobim.com/t/revit-api-python-how-to-get-elementid-of-builtincategory-enumeration/92138>\
**Category:** Developers\
**Tags:** python, dynamo, api\
**Created:** [July 25, 2023, 3:47am UTC](https://forum.dynamobim.com/t/revit-api-python-how-to-get-elementid-of-builtincategory-enumeration/92138 "2023-07-25T03:47:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsthomaspepe](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@itsthomaspepe](https://forum.dynamobim.com/u/itsthomaspepe)\
**Post date:** [July 25, 2023, 3:47am UTC](https://forum.dynamobim.com/t/revit-api-python-how-to-get-elementid-of-builtincategory-enumeration/92138/1 "2023-07-25T03:47:39Z")

</div>

In Dynamo RevitAPI 2021, i want to make a python node to call the BuiltInCategory Enumeration and get the ElementId of it. I want to filter the list containing elements by its Category properties ElementId compared to the BuiltInCategory ElementId. I tried using python dir() method on the BuiltInCategory but return nothing about properties or method that returned ElementId. How to get the Element Id?

Note: To Collect the Elements, i explicitly not use FilteredElementCollector and not using it’s WherePasses method. Just using the uidoc.Selection.GetElementIds() to get selected element in active view.

Here is the code:

```auto
#standard import boilerplate for Revit API
"""--- CODE STARTS HERE ---"""

builtincateg = BuiltInCategory.OST_DetailComponents #example builtincateg DetailComponent

elems = [] #example containing Elements collected from revit selection
filtered = []

for i in elems:
    idata = UnwrapElement(i)
    icateg = idata.Category.Id
    # why i use ElementId instead of Name because for BuiltInCategory returned "DetailComponents"
    # the i.Category.Name returned "Detail Items" and not "DetailComponents"
    # Cannot check matching

    if icateg.Id == builtincateg.Id: 
        #this check if ElementId same but error because builtincateg don't have ElementId properties
        filtered.append(i)
    else:
       pass

OUT = filtered
"""--- CODE END HERE ---"""

```

---

<div class="post-metadata">

**Author:** ![pyXam](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/pyxam/32/163009_2.png) [@pyXam](https://forum.dynamobim.com/u/pyXam)\
**Post date:** [July 25, 2023, 4:42am UTC](https://forum.dynamobim.com/t/revit-api-python-how-to-get-elementid-of-builtincategory-enumeration/92138/2 "2023-07-25T04:42:18Z")

</div>

To get element ID?

```auto
def GetId(item):
	if hasattr(item, "Id"): return item.Id.IntegerValue
	else: return None

items = UnwrapElement(IN[0])

if isinstance(IN[0], list): OUT = [GetId(x) for x in items]
else: OUT = GetId(items)

```

Is this what you are trying to do?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/5/f58752396cd91a22b4ec582408c73fdc8d368dde.png)

---

<div class="post-metadata">

**Author:** ![itsthomaspepe](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@itsthomaspepe](https://forum.dynamobim.com/u/itsthomaspepe)\
**Post date:** [July 25, 2023, 8:46am UTC](https://forum.dynamobim.com/t/revit-api-python-how-to-get-elementid-of-builtincategory-enumeration/92138/3 "2023-07-25T08:46:41Z")

</div>

Thanks for the reply @pyXam  
As you noted in your image. I found the script to get the data of API BuiltInCategory [Clockwork.BuiltInCategories](https://github.com/andydandy74/ClockworkForDynamo/blob/1d24f41f545296e6508db29b95ae491917541286/nodes/2.x/python/Document.BuiltInCategories.py) node. Thanks @Andreas_Dieckmann for the package

Those custom node do the job to get 1. BuiltInCategory, 2. BuiltInCategory ElementId, 3. BuiltInCategory Revit Category. And using the import System, i can use System.Enums.GetValues(BuiltInCategories) to get all list of RevitAPI BuiltInCategories in this [RevitAPI BuiltInCategory Enumeration](https://www.revitapidocs.com/2021.1/ba1c5b30-242f-5fdc-8ea9-ec3b61e6e722.htm)

Here are the finished script

```auto
#standard import boilerplate for Revit API
"""--- CODE STARTS HERE ---"""

#1.List of All BuiltInCategory Enumeration in RevitAPI
#no need for this script because already specified the builtincategory
import System.Enum 
biclist = System.Enum.GetValues(BuiltInCategory)

#init builtin object as variable
builtincateg = BuiltInCategory.OST_DetailComponents #example builtincateg DetailComponent

#2. Get Revit ElementId of the BuiltInCategory object  
builtincategId = ElementId(builtincateg)

#3. Get the Revit Category (object class same as Element.Category)
biccategRevit = Revit.Elements.Category.ById(ElementId(builtincateg).IntegerValue)

elems = [] #example containing Elements collected from revit selection
filtered = []

for i in elems:
	idata = UnwrapElement(i)
	icateg = idata.Category.Id
	if icateg.Id == builtincategId: 
		filtered.append(i)
	else:
		pass

OUT = filtered
"""--- CODE END HERE ---"""

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [July 25, 2023, 3:41pm UTC](https://forum.dynamobim.com/t/revit-api-python-how-to-get-elementid-of-builtincategory-enumeration/92138/4 "2023-07-25T15:41:30Z")

</div>

Hi,

you can use this constructor

> **[ElementId Constructor (BuiltInCategory)](https://www.revitapidocs.com/2023/8251e7b1-ea91-ec9c-c8da-6f53a6638811.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018
