Getting info about rooms

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.

selectedRoom

Advertisements

4 thoughts on “Getting info about rooms

  1. Excellent. So that will essentially allow you to display, in a popup window, properties of the room. I added to also show Area (room.Area). Before I get into my first question, I’m curious to know how I could ‘display’ my information a bit better. How do I add text, prior to the property, saying “Room Number =” and then show the value?

    Now will this only allow you to pull system properties, correct (i.e. it won’t allow me to pull project parameters I add)? Is it possible to pull project parameters?

    • >> How do I add text, prior to the property, saying “Room Number =” and then show the value?

      You can add any strings you want to the string that the TaskDialog shows. The “+” is the string concatenation operator in C# and “+=” appends.. You can also store the string in a variable and then use the variable in TaskDialog.Show.

      string roomInfo = “The room name is ” + room.Name + “\n”;
      roomInfo += “The room number is ” + room.Number;
      TaskDialog.Show(“Room Info”, roomInfo);

      >> Now will this only allow you to pull system properties, correct (i.e. it won’t allow me to pull project parameters I add)?

      This approach allows you to get properties of the Room class. For example, room.Perimeter, room.Volume, room.Level, etc.
      To get other parameters, take a look at the use of e.get_Parameter at https://boostyourbim.wordpress.com/2012/12/03/resolving-duplicate-tags-step-3-get-set-parameter-values/
      (for this example, replace e with room)

      • just getting back to this one. thanks! works great. basic concept I know…but making the connections! appreciate the help. i will take a look at the e.get_Parameter shortly!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s