Hello everyone!
I would like to know if there is a way to compare every element on a list with the elements of another list. If the comparisson matches, it should retrieve an element. The part of the script that i have its already working but by taking one of lists index, but istead, i would like it to do it by a loop.
Here’s the part of the code that its already working
rmLst = IN[0]
Seleccionar habitaciones
rmsTyp = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
Filtrar habitaciones por lista
rmsWR =
for rms in rmsTyp :
rmNm = rms.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
if (rmNm == rmLst[0]) or (rmNm == rmLst[1]) :
rmsWR.append(rms)

@fc.castro113
here your code pasted correctly </>
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Access the Revit application and document
app = DocumentManager.Instance.CurrentUIApplication
doc = DocumentManager.Instance.CurrentDBDocument
rmLst = IN[0]
# Seleccionar habitaciones
rmsTyp = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
# Filtrar habitaciones por lista
rmsWR = []
for rms in rmsTyp :
rmNm = rms.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
if (rmNm == rmLst[0]) or (rmNm == rmLst[1]) :
rmsWR.append(rms)
@fc.castro113
in dynamo you can use dictionary
i just added to the code a OUT
it works too
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Access the Revit application and document
app = DocumentManager.Instance.CurrentUIApplication
doc = DocumentManager.Instance.CurrentDBDocument
room_names_desired_list = IN[0]
# Seleccionar habitaciones
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
# Filtrar habitaciones por lista
rooms_name_match = []
for room in rooms:
room_name = room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
if (room_name == room_names_desired_list[0]) or (room_name == room_names_desired_list[1]) :
rooms_name_match.append(room)
OUT = rooms_name_match
It would be helpful to know exactly what you’re doing and where your values are coming from. If you have a list of names and you want to get the associated room based on a specific order, then a dictionary is best.
If you have a list of names and you want to know if your list of rooms match those names then you can just check for matches by confirming the room name is in the list of names like this:
for rms in rmsTyp:
if rms.get_Parameter(BuiltInParameter.ROOM_NAME).AsString() in rmLst:
rmsWR.append(rms)
Your only input is a list of names to match and use an OR condition for the matching so I’m guessing your use case is the one above. If you want the rooms in the same order as the named list then you just need to loop through that list first (as an alternative to the dictionary method).
for rmLstNm in rmLst:
for rms in rmsTyp:
if rms.get_Parameter(BuiltInParameter.ROOM_NAME).AsString() == rmLstNm:
rmsWR.append(rms)
2 Likes
Thanks sorry i didnt know how to post it correctly
Well, actually i dont know if a dictionary could work. Lets say that i have a large number of rooms and i just want to pick the ones named “toilet” so i can work with those later. Yes this code works like that, and its similar as the one i post (sorry i didnt post it complete), but i would like to know if this part of the code:
if (room_name == room_names_desired_list[0]) or (room_name == room_names_desired_list[1]) :
could be replaced by a list of elements so i dont have to input every element separetly
Thanks a lot for ur replay
@Nick_Boyts the second solution works perfect. You were right, the values that i have are a number of rooms retrieved from revit and a list of names which i wanted to use as a filter to select the rooms that matches those names. Thanks a lot for your solution!