Hi All,
I’m collecting rooms and I’d like their name displayed in a pyRevit form but the name_attr
gives me an error. I’m not sure if there is another way. Do I need to get the rooms name manually ?
mycode
from pyrevit import forms
from Autodesk.Revit.DB import *
doc = __revit__.ActiveUIDocument.Document
rooms = FilteredElementCollector(doc)\
.WherePasses(Architecture.RoomFilter())\
.ToElements()
res = forms.SelectFromList.show(rooms,
multiselect=True,
name_attr='Name',
button_name='Select Room')
print (res)
scartmell
(Stewart Cartmell)
October 27, 2022, 7:57pm
#2
You might have to use
room.LookupParameter("Room Name")
to access the Room Name parameter
2 Likes
shampoon
(kaszel)
February 21, 2023, 1:42pm
#3
How to compose this phrase within SelectFromList?
When I am trying it this way:
forms.SelectFromList.show(rooms,
multiselect=True,
name_attr=room.LookupParameter("Room Name")
button_name='Select Room')
I am having the error
Also
forms.SelectFromList.show(rooms,
multiselect=True,
name_attr=LookupParameter("Room Name")
button_name='Select Room')
is not working.
you will probably have to do it as a list comprehension
name_attr = [i.LookupParameter(“Room Name”) for i in rooms]
shampoon
(kaszel)
February 22, 2023, 11:27am
#5
Unfortunately it won’t work
res = forms.SelectFromList.show(rooms,
multiselect=True,
name_attr=[i.LookupParameter("Room Name") for i in rooms],
button_name='Select Room')
eirannejad
(Ehsan Iran-Nejad)
February 22, 2023, 4:57pm
#6
@shampoon Try Element.Name.GetValue(i)
to get the name (i
is the element instance in this example)
2 Likes
thumDer
(Tamás Déri)
February 26, 2023, 3:50pm
#7
It won’t work this way. You’ll have to use a custom ListItem
class that inherits from forms.TemplateListItem
and override the name property there with the method @eirannejad suggested. I can show you an example once I’ll be in front of a pc.
shampoon
(kaszel)
February 26, 2023, 6:35pm
#8
@thumDer
I will be grateful if you can share mentioned example.
thumDer
(Tamás Déri)
February 26, 2023, 8:41pm
#9
Okay, so you will need to implement a new class like
class RoomListItem(forms.TemplateListItem):
@property
def name(self):
return Element.Name.GetValue(self.item)
for the list of rooms you need to have a list of these items made from the original rooms like
rooms = [RoomListItem(room) for room in rooms]
and when you create the UI with SelectFromList
you won’t need the name_attr
1 Like
shampoon
(kaszel)
February 27, 2023, 7:34am
#10
@thumDer
when having the example it looks very easy, but without it I was not able to solve my issue.
Many thanks, it is working now!
1 Like