サーフェスにアクセスする

図面内のサーフェス オブジェクトには、さまざまな方法でアクセスすることができます。ドキュメントに含まれるすべてのサーフェスは、CivilDocument.GetSurfaceIds() メソッドを使用して取得できます。このメソッドは、ObjectIdCollection を返します。

ObjectIdCollection SurfaceIds = doc.GetSurfaceIds();
foreach (ObjectId surfaceId in SurfaceIds)
{
    CivSurface oSurface = surfaceId.GetObject(OpenMode.ForRead) as CivSurface;
    editor.WriteMessage("Surface: {0} \n  Type: {1}", oSurface.Name, oSurface.GetType().ToString());

}

また、Autodesk.AutoCAD.DatabaseServices 名前空間にサーフェス クラスもあります。この名前空間は、Autodesk.Civil.DatabaseServices.Surface と競合することに注意してください(両方の名前空間を使用する場合)。この場合は、完全にサーフェス オブジェクトにするか、"using" エイリアス ディレクティブを使用して参照の曖昧さを解消することができます。例:

using CivSurface = Autodesk.Civil.DatabaseServices.Surface;

その後、次のようなエイリアスを使用します。

CivSurface oSurface = surfaceId.GetObject(OpenMode.ForRead) as CivSurface;

また、TIN サーフェスなどの特定のサーフェス タイプを選択するようユーザに要求し、次にその選択からサーフェス ID を取得することもできます。

private ObjectId promptForTinSurface(String prompt)
{
    PromptEntityOptions options = new PromptEntityOptions(
        String.Format("\n{0}: ", prompt));
    options.SetRejectMessage(
        "\nThe selected object is not a TIN Surface.");
    options.AddAllowedClass(typeof(TinSurface), true);

    PromptEntityResult result = editor.GetEntity(options);
    if (result.Status == PromptStatus.OK)
    {
        // We have the correct object type
        return result.ObjectId;
    }
    return ObjectId.Null;   // Indicating error.
}