A friendly member of the new BoostYourBIM fan club wrote with some suggestions that we might be able to some interesting things with rooms.
In the last example a basic filter was used to get all the doors. The other main way to get elements is with selection, which I will use here.
There are these two “using” statements to add for this code:
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;
And here is the code to select a room and show some basic information about it.
public void RoomElements()
{
Document document = this.ActiveUIDocument.Document;
UIDocument uidoc = new UIDocument(document);
Reference reference = uidoc.Selection.PickObject(ObjectType.Element);
Element element = document.GetElement(reference);
Room room = element as Room;
TaskDialog.Show("Room Data",room.Name + "\n" + room.Number);
}
The UIDocument is a class that handles the “UI”, as opposed to the database (DB) of Revit. This primarily involves views and selection. The constructor creates a UIDocument from a DB Document.
The Reference class is used to reference elements in the documents. A popular thing to do with it is to get the element that it refers to, which is done on the following line.
Then the element is converted into a room using the “as” operator to do the cast conversion.
Finally, a Task Dialog is used to display the room name and number. As the image below shows, a “quirk” of the API is that room.Name includes the room name and number.

Like this:
Like Loading...