# Get Element's Room PYTHON

**URL:** <https://forum.dynamobim.com/t/get-elements-room-python/73577>\
**Category:** Developers\
**Tags:** python\
**Created:** [February 22, 2022, 5:10am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577 "2022-02-22T05:10:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoniocanerosan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/antoniocanerosan/32/131219_2.png) [@antoniocanerosan](https://forum.dynamobim.com/u/antoniocanerosan)\
**Post date:** [February 22, 2022, 5:10am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/1 "2022-02-22T05:10:15Z")

</div>

Hi everyone,

Can anyone advise how to get the room numbers from a list of elements? Using ONLY PYTHON.

Thanks!

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [February 22, 2022, 6:24am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/2 "2022-02-22T06:24:33Z")

</div>

Lots of options, but doubtful your content is set to do them all at scale.

RoomAtPoint method is likely easiest to implement. [GetRoomAtPoint Method](https://www.revitapidocs.com/2022/abe7af79-92f3-be8e-595f-8666dc6ba86b.htm)

---

<div class="post-metadata">

**Author:** ![antoniocanerosan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/antoniocanerosan/32/131219_2.png) [@antoniocanerosan](https://forum.dynamobim.com/u/antoniocanerosan)\
**Post date:** [March 10, 2022, 6:24am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/3 "2022-03-10T06:24:59Z")

</div>

Thanks @jacob.small

I was trying to use script, that has been working good for other BuiltInParameter, however, none of the following BuiltIn Parameter values are retrieving the Room Name from the elements:

SPACE\_ASSOC\_ROOM\_NAME  
ROOM\_NAME  
ELEM\_ROOM\_NAME

```auto
import clr

clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

import Autodesk
import RevitServices

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

collector = FilteredElementCollector(doc)
toList = lambda x : x if hasattr(x, ' __iter__') else [x]
lstelems = toList(UnwrapElement(IN[0]))

myInternalParameters = []
for element in lstelems:
	for param in element.Parameters:
		paradef = param.Definition
		if not param.IsShared and isinstance(paradef, InternalDefinition):
			if paradef.BuiltInParameter == BuiltInParameter.SPACE_ASSOC_ROOM_NAME :
				elementname = element.get_Parameter(BuiltInParameter.SPACE_ASSOC_ROOM_NAME)
				paramvalue = elementname.AsString()
				parameterstoragetype = elementname.StorageType
				myInternalParameters.append(paramvalue)
# myInternalParameters.append([param.Definition.Name, paramvalue, parameterstoragetype])

OUT = myInternalParameters

```

Any help would be appreciated…

Thanks

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [March 10, 2022, 6:36am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/4 "2022-03-10T06:36:24Z")

</div>

Two questions:

What type of elements have you provided into the inputs?

Why are you sticking to just Python?

What do the elements show for these parameter values in Revit?

---

<div class="post-metadata">

**Author:** ![antoniocanerosan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/antoniocanerosan/32/131219_2.png) [@antoniocanerosan](https://forum.dynamobim.com/u/antoniocanerosan)\
**Post date:** [March 10, 2022, 6:58am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/5 "2022-03-10T06:58:00Z")

</div>

Hi @jacob.small

Thanks for the quick response.

1. Family Name [example below: Values under “Room Name” node. In this case, I have used: SYMBOL\_FAMILY\_NAME\_PARAM]  

2. This exercise is part of a bigger code. I need it to be all in Python with the intention to package it later.

3. I am trying to gather the Room/Name value. Please find bellow an example of casework element

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

Attached the code in case is useful.

Thanks  
[GetRoomName\_Example.dyn](https://forum.dynamobim.com/uploads/short-url/6veux8TGBzZj659RWU89rSV61lT.dyn) (10.6 KB)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [March 10, 2022, 12:59pm UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/6 "2022-03-10T12:59:27Z")

</div>

Gotcha based on #1 above. Not sold on why for #2 as you could always use nodes in the custom node, but I digress.

Instead of calling for the parameter call the method to get the room, as I recently showed here: [Family-Parameter(Window) based on nearness/enclosure to Room - #11 by JacobSmall](https://forum.dynamobim.com/t/family-parameter-window-based-on-nearness-enclosure-to-room/74014/11)

You do have a few elements which won’t have either the parameter nor the method to get the room (ie: system panels) so because of those you may have to add a big try/except to catch the failure points, or you’ll have to use a bunch of if statements to get things to gather the data without throwing an error. After the easy methods shown above I would move onto adding a loop to pull the location of the object, breaking each item down to a point, and using that to get the room at point.

You can add the many parameter methods which store room data in them, but I am not sure how those return data with phased projects (because that table has a room in the existing conditions, phase and a different room in the new construction phase). Depending on how many element types you find have the property for ‘room’ / ‘from room’ / ‘to room’ it might actually be better to skip it all and jump directly to the room at point method I noted before.

I’ll try to look over your code today to see if I can make it repeat the issues you’re having on a sample project, but I have a rather busy day today so no promises.

---

<div class="post-metadata">

**Author:** ![antoniocanerosan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/antoniocanerosan/32/131219_2.png) [@antoniocanerosan](https://forum.dynamobim.com/u/antoniocanerosan)\
**Post date:** [March 11, 2022, 2:25am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/7 "2022-03-11T02:25:49Z")

</div>

Thanks @jacob.small for looking at it.

Let me know if you take a look.

Thanks

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [March 11, 2022, 6:23am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/8 "2022-03-11T06:23:01Z")

</div>

So I am seeing a few things here.

Your method of collecting stuff is going to grab… we’ll all the things in the active view. Including stuff like detail items, rooms, view references, and the like. That isn’t likely to work well for finding the ‘room’ associated to the element as a lot of these won’t have a room.

What would you use for the room element for a wall that divides the hallway from six offices? What about the floor slab for the entire level?

You also are pulling the element type for all the selected elements. Try is means that 90% of the items wouldn’t have a room, as they don’t have a location in the model yet.

Your best bet is still going to be pulling the elements’s location, discarding anything not a ‘locationpoint’ type as the other element types don’t have a single room, convert to a point, and use the get room at point method to pull the room you’re after.

---

<div class="post-metadata">

**Author:** ![antoniocanerosan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/antoniocanerosan/32/131219_2.png) [@antoniocanerosan](https://forum.dynamobim.com/u/antoniocanerosan)\
**Post date:** [March 14, 2022, 12:01am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/9 "2022-03-14T00:01:24Z")

</div>

Thanks @jacob.small

I understand your point.

I have tried the same but using “Categories” + “All Elements of Category” nodes to gather all the Casework instances in the model (Which I know that they are placed in a Room), and still the “Room\_Name” python node won’t gather the info using any of the BuiltInParameters below.:

SPACE\_ASSOC\_ROOM\_NAME  
ROOM\_NAME  
ELEM\_ROOM\_NAME

I am happy to try to pull the element’s location and discard anything, not a ‘locationpoint’ as suggested. If you have any example would be appreciated.

Thanks in advance.

Cheers,

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [March 14, 2022, 12:11am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/10 "2022-03-14T00:11:17Z")

</div>

Not at a computer and just typing this on my phone so you’ll have to do some severe edits, but something like this might work:

```auto
elems = IN[0]
phase = IN[1]
results = []

for elem in elems:
   loc = elem.Location
   if loc.ToString() != Autodesk.Revit.DB.LocationPoint:
      results.append(“Element Is Not Point Based”)
   else:
      pnt = loc.Point
      rm = doc.GetRoomAtPoint(pnt,phase)
      results.append(rm)
OUT = results

```

---

<div class="post-metadata">

**Author:** ![antoniocanerosan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/antoniocanerosan/32/131219_2.png) [@antoniocanerosan](https://forum.dynamobim.com/u/antoniocanerosan)\
**Post date:** [March 14, 2022, 12:22am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/11 "2022-03-14T00:22:44Z")

</div>

Thanks @jacob.small appreciate your help!

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [March 14, 2022, 12:35am UTC](https://forum.dynamobim.com/t/get-elements-room-python/73577/12 "2022-03-14T00:35:54Z")

</div>

If that doesn’t work let me know - have some time tomorrow morning when I can try a few other things out.

Also, of these families are all in your library it might be better to enable the ‘room calculation point’ for them all, which would allow you to call the room parameter directly. I recall seeing a thread on this in bulk awhile back but not sure where it was.
