Hi everyone,
Can anyone advise how to get the room numbers from a list of elements? Using ONLY PYTHON.
Thanks!
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
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
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 @jacob.small
Thanks for the quick response.
Family Name [example below: Values under âRoom Nameâ node. In this case, I have used: SYMBOL_FAMILY_NAME_PARAM ]
This exercise is part of a bigger code. I need it to be all in Python with the intention to package it later.
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.
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.
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,
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 @jacob.small appreciate your help!
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.