PlanTopology Class

Another question raised by Jochen Reichert of the University of Stuttgart last week was the use of the PlanTopology class and its members, which include:

This class represents a plan topology within the Revit project and looks like it might be useful for handling rooms and areas, which could be used for analysis of cost and gross versus net floor area, volume, or facility management. Each of the circuits managed by this class represents an enclosed area in a plan view and provides members including:

Harry Mattison of Autodesk provided the following background information and sample command CmdPlanTopology for testing this class:

PlanTopology contains information about the rooms and circuits on a specific level and phase. A circuit is a closed space bounded by walls where a room can be created. The simple example below reports information about the rooms that already exist and creates new rooms in circuits that don't have rooms. We are aware of some ideas about how circuits and the PlanCircuit class could be improved, which are part of a wish list item that might give you some further ideas about the potential future use of circuits and the plan topology class:

Here is the example that reports information about the rooms that already exist and creates new rooms in circuits that don't have rooms.

Application app = commandData.Application;
Document doc = app.ActiveDocument;
 
List<Element> list = new List<Element>();
 
Filter f = app.Create.Filter.NewTypeFilter(
  typeof( Level ) );
 
int n = doc.get_Elements( f, list );
Level level = list[0] as Level;
 
PlanTopology pt = doc.get_PlanTopology( level );
 
string output = "Rooms on "
  + level.Name + ":"
  + "\n  Name and Number : Area";
 
foreach( Room r in pt.Rooms )
{
  output += "\n  " + r.Name + " : "
    + Util.RealString( r.Area ) + " sqf";
}
Util.InfoMsg( output );
 
output = "Circuits without rooms:"
  + "\n  Number of Sides : Area";
 
foreach( PlanCircuit pc in pt.Circuits )
{
  if( !pc.IsRoomLocated )
  {
    output += "\n  " + pc.SideNum + " : "
      + Util.RealString( pc.Area ) + " sqf";

    Room r = doc.Create.NewRoom( null, pc );
  }
}
Util.InfoMsg( output );

The code uses Revit 2009 API filters to determine the first level in the model. The plan topology of that level is retrieved and queried for all its rooms. In the first loop, the name and area of each room of the plan topology is queried and displayed in a message box. In the second loop, each circuit with no room is queried for its number of sides and area, and a new room is created for it. The method NewRoom can be called with an existing unplaced room to place it in the given circuit, or with a null argument to create a new room.

Here is the output generated by the first run in a simple model with two closed wall loops, only one of which has a room placed in it so far:

Rooms on Level 1:
  Name and Number : Area
  Room 1 : 278.14 sqf
Circuits without rooms:
  Number of Sides : Area
  4 : 114.53 sqf

In all subsequent runs after the first one, rooms have been created in each circuit, and the output changes to this:

Rooms on Level 1:
  Name and Number : Area
  Room 1 : 278.14 sqf
  Room 2 : 114.53 sqf
Circuits without rooms:
  Number of Sides : Area

Here is version 1.0.0.19 of the complete Visual Studio solution with the new command CmdPlanTopology discussed here.