AutoCAD Civil 3D Help: Accessing Surfaces

访问曲面


有很多方法可以访问一个图形中的曲面对象。一个图形中包含的所有曲面都可以通过CivilDocument.GetSurfaceIds()方法来取得,它返回的是一个ObjectId对象集合。

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

}

注意在Autodesk.AutoCAD.DatabaseServices命名空间中也有一个叫做Surface的类,如果你引用了这两个命名空间,它会和Autodesk.Civil.DatabaseServices.Surface产生冲突。这种情况下你可以通过完全限制该Surface对象,或者采用“using”使用别名来消除该引用的歧义。如:

using CivSurface = Autodesk.Civil.DatabaseServices.Surface;

然后如下使用该别名:

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

你也可以提示用户选择一个指定的曲面类型,例如一个三角网曲面,然后从选择集中取得曲面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.
}

父主题:

曲面

results matching ""

    No results matching ""