# Get a list of elements with their space number

Hi,
I’m trying to get the space number of the element from their Room Calculation Point.
It seems I have to use this class SpatialElementCalculationLocation but I don’t know how to use it :

For the moment I can get the Space number:

``````for s in SP:
numero = s.get_Parameter(BuiltInParameter.ROOM_NUMBER)
print(numero.AsString())
print(s.Id.IntegerValue)
``````

And the location of the element :

``````for ME in MEs:
loc = ME.Location.Point
print(loc.X, loc.Y, loc.Z)
``````

But I don’t know how to link them. Is there an API native way to do this or I have to build a script with the volume of the spaces and the element locations ?

Welcome,

two approaches for Rooms

``````def element_room(item,phase):
return item.Room[phase]

elements_rooms = [element_room(x,phase) for x in items]
``````

or

``````for family in fam_symbols:
try:
pt = family.Location.Point
except:
pt = family.Location.Curve.Origin
for room in rooms:
if room.IsPointInRoom(pt):
``````

Thank you for the tips !

I just replace item.Room by item.Space for my need.
I’m sharing my code for those who can help :

``````phase = doc.Phases[1]

MEs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_MechanicalEquipment).WhereElementIsNotElementType().ToElements()

def element_room(item,phase):
return item.Space[phase]

elements_spaces = [element_room(x,phase) for x in MEs]

print(elements_spaces[0].Name)
``````
1 Like

Hi @Yoann.Obry and @Jean-Marc!
I develop a script for this topic but with a different approach. My goal was to get the room name and number for my MEP element without the need to create MEP space. Use spaces only to get the room information isn’t the best use for the spaces. So, I use 3 method in the script to obtain the better result.

• BoundingBox
• Centroïd
• Instance Origin

Once the script get where is the MEP element are located, I get the room name and number and i copy this information to my shared parameter. Finally, I get the same information if I compare with the spaces method, but more flexibilities because the data are store in shared parameter.