GridSurface.Create() を使用して GridSurface を作成する

GridSurface.Create() メソッドを使用して、空の GridSurface を作成することができます。このメソッドには 2 つのオーバーロードがあります。1 つは既定の SurfaceStyle を適用し、もう 1 つは使用する SurfaceStyle を指定できます。両方とも、新しい GridSurface の名前、X および Y 方向の間隔、および方向を指定します。X および Y 方向の間隔および方向の単位は、サーフェス作成環境設定(SettingsCmdCreateSurface Distance および Area プロパティ)で指定します。

GridSurface オブジェクトは、一定間隔のグリッド上で定義され、グリッド上の各場所(GridLocation 構造で表現)には、行インデックスと列インデックスがあります。グリッド アドレス (0,0) は、グリッドの左下コーナーです。

次の例では、25' x 25' 間隔の新しい空の GridSurface を作成し、10 x 10 グリッドまで繰り返して、各サンプル場所にランダムに標高を追加します。

[CommandMethod("CreateGridSurface")]
public void CreateGridSurface()
{
    using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
    {
        string surfaceName = "ExGridSurface";
        // Select a surface style to use 
        ObjectId surfaceStyleId = doc.Styles.SurfaceStyles["Slope Banding (2D)"];

        // Create the surface with grid spacing of 25' x 25', orientation 0 degrees:
        ObjectId surfaceId = GridSurface.Create(surfaceName, 25, 25, 0.0, surfaceStyleId);
        GridSurface surface = surfaceId.GetObject(OpenMode.ForWrite) as GridSurface;

        // Add some random elevations
        Random m_Generator = new Random();
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {                        
                double z = m_Generator.NextDouble() * 10;
                GridLocation loc = new GridLocation(i, j);
                surface.AddPoint(loc, z);
            }
        }

        // commit the create action
        ts.Commit();
    }
}