Level Class


Represents a Level within Autodesk Revit.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 21.0.0.0 (21.1.1.109)

Syntax

C#
public class Level : DatumPlane
Visual Basic
Public Class Level _
	Inherits DatumPlane
Visual C++
public ref class Level : public DatumPlane

Remarks

A Level is conceptually a horizontal rectangle of finite extents. It appears as a straight line in views that intersect the rectangle. The straight line represents the projection of the rectangle onto the view. The Name property can be used to retrieve the user visible name of the level that appears in the level bubble.

Examples

Copy C#
private void GetLevelInformation(Autodesk.Revit.DB.Element element)
{
    // Get the level object to which the element is assigned.
    if (element.LevelId.Equals(ElementId.InvalidElementId))
    {
        TaskDialog.Show("Revit","The element isn't based on a level.");
    }
    else
    {
        Level level = element.Document.GetElement(element.LevelId) as Level;

        // Format the prompt information(Name and elevation)
        String prompt = "The element is based on a level.";
        prompt += "\nThe level name is:  " + level.Name;
        prompt += "\nThe level elevation is:  " + level.Elevation;

        // Show the information to the user.
        TaskDialog.Show("Revit",prompt);
    }
}
Copy C#
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());
}
Copy VB.NET
Private Sub GetLevelInformation(element As Autodesk.Revit.DB.Element)
    ' Get the level object to which the element is assigned.
    If element.LevelId.Equals(ElementId.InvalidElementId) Then
        TaskDialog.Show("Revit", "The element isn't based on a level.")
    Else
        Dim level As Level = TryCast(element.Document.GetElement(element.LevelId), Level)

        ' Format the prompt information(Name and elevation)
        Dim prompt As [String] = "The element is based on a level."
        prompt += vbLf & "The level name is:  " + level.Name
        prompt += vbLf & "The level elevation is:  " + level.Elevation

        ' Show the information to the user.
        TaskDialog.Show("Revit", prompt)
    End If
End Sub
Copy VB.NET
Private Sub Getinfo_Level(document As Document)
    Dim levelInformation As New StringBuilder()
    Dim levelNumber As Integer = 0
    Dim collector As New FilteredElementCollector(document)
    Dim collection As ICollection(Of Element) = collector.OfClass(GetType(Level)).ToElements()
    For Each e As Element In collection
        Dim level As Level = TryCast(e, Level)

        If level IsNot Nothing Then
            ' keep track of number of levels
            levelNumber += 1

            'get the name of the level
            levelInformation.Append(vbLf & "Level Name: " + level.Name)

            'get the elevation of the level
            levelInformation.Append(vbLf & vbTab & "Elevation: " + level.Elevation)

            ' get the project elevation of the level
            levelInformation.Append(vbLf & vbTab & "Project Elevation: " + level.ProjectElevation)
        End If
    Next

    'number of total levels in current document
    levelInformation.Append(vbLf & vbLf & " There are " & levelNumber & " levels in the document!")

    'show the level information in the messagebox
    TaskDialog.Show("Revit", levelInformation.ToString())
End Sub

Inheritance Hierarchy

See Also