DEM ファイルからグリッド サーフェスを作成する

GridSurface.CreateFromDEM() メソッドを使用して、数値標高モデル(DEM)ファイルから GridSurface を作成できます。このメソッドは 2 つのオーバーロードを備えています。1 つは既定のスタイルを適用するオーバーロード、もう 1 つは、使用する SurfaceStyle を指定することができます。どちらも、DEM ファイルのファイル名とパスを文字列として受け取ります。

[CommandMethod("CreateFromDEM")]
public void CreateFromDEM()
{
    using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
    {
        // Prompt user for a DEM file:
        // string demFile = @"C:\Program Files\Autodesk\AutoCAD Civil 3D 2013\Help\Civil Tutorials\Corridor surface.tin";
        PromptFileNameResult demResult = editor.GetFileNameForOpen("Enter the path and name of the DEM file to import:");
        editor.WriteMessage("Importing: {0}", demResult.StringResult);

        try
        {
            // surface style #3 is "slope banding" in the default template
            ObjectId surfaceStyleId = doc.Styles.SurfaceStyles[3];
            ObjectId gridSurfaceId = GridSurface.CreateFromDEM(demResult.StringResult, surfaceStyleId);
            editor.WriteMessage("Import succeeded: {0} \n", gridSurfaceId.ToString());
        }
        catch (System.Exception e)
        {
            // handle bad file data or other errors
            editor.WriteMessage("Import failed: {0}", e.Message);
        }

        // commit the transaction
        ts.Commit();
    }
}