A level is a finite horizontal plane that acts as a reference for level-hosted elements, such as walls, roofs, floors, and ceilings.
In the Revit Platform API, the Level class is derived from the DatumPlane class, which is derived from the Element class. The inherited Name property is used to retrieve the user-visible level name beside the level bubble in the Revit UI. To retrieve all levels in a project, use an ElementClassFilter with the Level class.
The Level class has the following properties:
0 corresponds to Project and 1 corresponds to Shared.
The following code sample illustrates how to retrieve all levels in a project using a Level class filter.
Code Region 15-1: Retrieving all Levels |
private void Getinfo_Level(Document document) { StringBuilder levelInformation = new StringBuilder(); int levelNumber = 0; FilteredElementCollector collector = new FilteredElementCollector(document); ICollection<Element> collection = collector.OfClass(typeof(Level)).ToElements(); foreach (Element e in collection) { Level level = e as Level; if (null != level) { // keep track of number of levels levelNumber++; //get the name of the level levelInformation.Append("\nLevel Name: " + level.Name); //get the elevation of the level levelInformation.Append("\n\tElevation: " + level.Elevation); // get the project elevation of the level levelInformation.Append("\n\tProject Elevation: " + level.ProjectElevation); } } //number of total levels in current document levelInformation.Append("\n\n There are " + levelNumber + " levels in the document!"); //show the level information in the messagebox TaskDialog.Show("Revit",levelInformation.ToString()); } |
Using the Level command, you can define a vertical height or story within a building and you can create a level for each existing story or other building references. Levels must be added in a section or elevation view. Additionally, you can create a new level using the Revit Platform API.
The following code sample illustrates how to create a new level.
Code Region 15-2: Creating a new Level |
Level CreateLevel(Autodesk.Revit.DB.Document document) { // The elevation to apply to the new level double elevation = 20.0; // Begin to create a level Level level = Level.Create(document, elevation); if (null == level) { throw new Exception("Create a new level failed."); } // Change the level name level.Name = "New level"; return level; } |