Getting the Name of a room object

1,652 views
Skip to first unread message

Iffat Mai

unread,
Oct 10, 2012, 5:40:04 PM10/10/12
to revitpyt...@googlegroups.com
As I was writing this message, I figured out the answer to my own question before I can post the question, so I will just share the solution with the group.

I'm using a simple python code to get room information.
The codes retrieves the room objects from the document, and using a simple print command, I can access the room number and area, but when it gets to room name, it tells me it can't find the attribute(Name), even though it is clearly listed as a parameter both in Revit API, as well as using python DIR() command.

If I call it using room.Name
then I get the error "AttributeError: Name"

If I call it using room.Parameter('Name")
then I get the error "TypeError: indexer# is not callable"

After trying to get to the names using all different ways, I finally got it to work
print room.get_Parameter('Name').AsString()

This is certainly something that is different from using C# or VB.net, where you can just use object.Name to get the name.
and I don't know why it has such a hard time getting the name out of a room object.

Iffat

Daren Thomas

unread,
Oct 15, 2012, 9:02:42 AM10/15/12
to revitpyt...@googlegroups.com
Hello Iffat,

I ran into a similar problem with accessing the Floor.Name property
and wrote a small blog post about it:

http://darenatwork.blogspot.ch/2012/10/rps-script-to-print-list-of-floor-types_1719.html

I think you can try to do this too:

# get Room.Name property instead of the stupid "Attribute error" message
Element.Name.GetValue(your_room_object)

I have not got around to poking in the RevitAPI.dll yet, but I suspect
the way the Revit dll is produced (with Revit not being a C#
application) might be the reason for this - IronPython is getting some
IL that it doesn't quite understand and therefore needs to be told how
to retrieve the property. But this is just a wild guess on my part and
I will check into it if I find time...

Regards,
Daren

Iffat Mai

unread,
Oct 19, 2012, 11:50:30 AM10/19/12
to revitpyt...@googlegroups.com
Hi Daren,
Perfect, the Element.Name.GetValue(object) works like a charm.
I tried it to get a family name and it works.

Thanks
Iffat

Татьяна И

unread,
Feb 15, 2021, 4:09:47 PM2/15/21
to RevitPythonShell
Iffat, thank you for this. i'm just trying to do first steps in Revit Dynamo and could not solve the simullar problem.Thanks to that old post my problem is solved. Thanks a lot.

четверг, 11 октября 2012 г. в 01:40:04 UTC+4, iffa...@gmail.com:

Katharine Fewings

unread,
Jul 26, 2023, 4:53:55 AM7/26/23
to RevitPythonShell
Hey I have a similar problem but I'm trying to get the name of the room that a family instance is in. Any suggestions? 

I tried:


As it was similar to:

family_instance.Location.Point 

(which produces the XYZ co-ordinate) 
but with Space.Name I'm getting: 

AttributeError: 'indexer#' object has no attribute 'Name' 

Any help would be greatly appreciated

Alberto Detrell

unread,
Oct 6, 2023, 6:03:48 PM10/6/23
to RevitPythonShell
Hi everyone,

I was looking for an answer to this issue and found this group.

I get it using another way. To get the name of a room or an area, you can use the BuiltInParameter for Room Name.
As it could be used in many cases where the property. Name is only a write-only parameter like in this case.

areaName = user_Area.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()

Let me know if it is working for you.

David Koch

unread,
Mar 29, 2024, 9:56:42 AM3/29/24
to RevitPythonShell
@Alberto Detrell - Thank you for that! 
  • room.get_Parameter('Name').AsString() did not work for me.
  • Element.Name.GetValue(your_room_object) worked, but it returned the room name and number, with a space in between.
  • room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString() returned just the room name.
  • room.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString() returned just the room number (which I do not need right now, but may in the future).

Reply all
Reply to author
Forward
0 new messages