通芯

Grid クラスは Autodesk Revit 内の 1 つのグリッド線を表します。

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

曲線

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 + ")";
}

通芯を作成する

Grid クラスでは 2 つのオーバーロードした Create()メソッドを使用して Revit プラットフォーム API で新しいグリッドを作成できます。次のメソッドをパラメータを変えて使用することによって、曲線の通芯や直線の通芯を作成できます。

コード領域 15-4: Grid.Create()

public Grid Create( Document document, Arc arc );
public Grid Create( Document document, 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 = Grid.Create(document, 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 = Grid.Create(document, 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 で通芯を作成すると、数値またはアルファベット順に自動的に名前が付けられます。