グリッド

グリッド

グリッドは、Element クラスから派生する Grid クラスによって表されます。グリッドのプロパティとメソッドをすべて持っています。継承された名前プロパティを使用して、グリッド ラインのグリッド記号のコンテンツを取得します。

曲線

Grid クラスの Curve プロパティは、グリッド ライン ジオメトリを表すオブジェクトを取得します。

  • IsCurved プロパティが True を返す場合、Curve プロパティは Arc クラスのオブジェクトになります。
  • IsCurved プロパティが False を返す場合、Curve プロパティは Line クラスのオブジェクトになります。

詳細は、「ジオメトリ」を参照してください。

次のコードは、Grid クラスの単純な使用例です。コマンド呼び出し後、結果はメッセージ ボックスに表示されます。

コード領域 15-3: Grid クラスを使用

public void GetInfo_Grid(Grid grid)
{
    string message = "Grid : ";

    // Show IsCurved property
    message += "\nIf grid is Arc : " + grid.IsCurved;

    // Show Curve information
    Autodesk.Revit.DB.Curve curve = grid.Curve;
    if (grid.IsCurved)
    {
        // if the curve is an arc, give center and radius information
        Autodesk.Revit.DB.Arc arc = curve as Autodesk.Revit.DB.Arc;
        message += "\nArc's radius: " + arc.Radius;
        message += "\nArc's center:  (" + XYZToString(arc.Center);
    }
    else
    {
        // if the curve is a line, give length information
        Autodesk.Revit.DB.Line line = curve as Autodesk.Revit.DB.Line;
        message += "\nLine's Length: " + line.Length;
    }
    // Get curve start point
    message += "\nStart point: " + XYZToString(curve.GetEndPoint(0));
    // Get curve end point
    message += "; End point: " + XYZToString(curve.GetEndPoint(0));

    TaskDialog.Show("Revit",message);
}

// output the point's three coordinates
string XYZToString(XYZ point)
{
    return "(" + point.X + ", " + point.Y + ", " + point.Z + ")";
}

グリッドを作成する

Revit プラットフォーム API で新しいグリッドを作成する場合、2 つのオーバーロードされた Document メソッドを使用できます。次のメソッドをパラメータを変えて使用することによって、曲線のグリッドや直線のグリッドを作成できます。

コード領域 15-4: NewGrid()

public Grid NewGrid( Arc arc );
public Grid NewGrid( Line line );
注: グリッドの作成に使用する円弧や線分は水平平面上にある必要があります。

次のコード サンプルは、線分や円弧を使用して新しいグリッドを作成する方法を表しています。

コード領域 15-5: 線分または円弧でグリッドを作成

void CreateGrid(Autodesk.Revit.DB.Document document)
{
    // Create the geometry line which the grid locates
    XYZ start = new XYZ(0, 0, 0);
    XYZ end = new XYZ(30, 30, 0);
    Line geomLine = Line.CreateBound(start, end);

    // Create a grid using the geometry line
    Grid lineGrid = document.Create.NewGrid(geomLine);
           
    if (null == lineGrid)
    {
        throw new Exception("Create a new straight grid failed.");
    }

    // Modify the name of the created grid
    lineGrid.Name = "New Name1";
    
    // Create the geometry arc which the grid locates
    XYZ end0 = new XYZ(0, 0, 0);
    XYZ end1 = new XYZ(10, 40, 0);
    XYZ pointOnCurve = new XYZ(5, 7, 0);
    Arc geomArc = Arc.Create(end0, end1, pointOnCurve);

           
    // Create a grid using the geometry arc
    Grid arcGrid = document.Create.NewGrid(geomArc);
           
    if (null == arcGrid)
    {
        throw new Exception("Create a new curved grid failed.");
    }

    // Modify the name of the created grid
    arcGrid.Name = "New Name2";
}
注: Revit でグリッドを作成すると、数値またはアルファベット順に自動的に名前が付けられます。

CurveArray パラメータを取る Document.NewGrids()メソッドを使用することによって、複数のグリッドを一度に作成することもできます。