レベルは有限の水平面で、壁、屋根、床、天井などのレベルにホストされる要素の参照面となります。
Revit プラットフォーム API では、Level クラスは DatumPlane クラスから派生し、 DatumPlane クラスは Element クラスから派生します。継承された Name プロパティは、Revit UI の通芯記号の横にあるユーザが認識できるレベル名を取得するために使用されます。プロジェクト内のすべてのレベルを取得するには、Level クラスで ElementClassFilter を使用します。
Level クラスには次のプロパティがあります。
0 はプロジェクト、1 は共有を表します。
次のコード サンプルは、Level クラス フィルタを使用してプロジェクトのすべてのレベルを取得する方法を表しています。
|
コード領域 15-1: すべてのレベルを取得 |
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());
}
|
[レベル]コマンドを使用すると、建物内の垂直方向の高さや階を設定し、既存の各階や他の建物参照にレベルを作成できます。レベルは、断面図ビューまたは立面図ビューに追加する必要があります。さらに、Revit プラットフォーム API を使用して新しいレベルを作成できます。
次のコード サンプルでは、新しいレベルを作成する方法を示します。
|
コード領域 15-2: 新しいレベルを作成 |
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;
}
|