Get Element's Room PYTHON

Hi everyone,

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

Thanks!

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

RoomAtPoint method is likely easiest to implement. GetRoomAtPoint Method

1 Like

Thanks @JacobSmall

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

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

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?

Hi @JacobSmall

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

Attached the code in case is useful.

Thanks
GetRoomName_Example.dyn (10.6 KB)

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

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.

1 Like

Thanks @JacobSmall for looking at it.

Let me know if you take a look.

Thanks

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.

1 Like

Thanks @JacobSmall

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,

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:

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

Thanks @JacobSmall appreciate your help!

1 Like

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.