Levels

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.

Elevation

The Level class has the following properties:

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());
}

Creating a Level

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;
}
Note: After creating a new level, Revit does not create the associated plan view for this level. If necessary, you can create it yourself. For more information about how to create a plan view, refer to Plan Views.