AutoCAD Civil 3D Help: Surface Properties

曲面属性


曲面对象开放了通用的曲面属性,你可以通过GetGeneralProperties()方法来访问它。计算并返回属性是一个很占用资源的过程,所以建议只调用该方法一次,对返回对象进行再利用,而不是为每个属性都调用该方法。三角网曲面和网格曲面有指定类型的属性(可以通过GetTinProperties() and GetGridProperties()获取)。这两种曲面也都实现了GetTerrainProperties()方法。

下面的例子获取了数据库中第一个曲面的通用属性,然后根据曲面类型来获取三角网曲面或网格曲面(特定)属性:

[CommandMethod("SurfaceProperties")]
public void SurfaceProperties()
{
    using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
    {
        try
        {
            // Get the first surface in a document    
            // "doc" is the CivilApplication.ActiveDocument
            ObjectId surfaceId = doc.GetSurfaceIds()[0];
            CivSurface oSurface = surfaceId.GetObject(OpenMode.ForRead) as CivSurface;

            // print out general properties: TiStar Translated @ 2018/04/05
            GeneralSurfaceProperties genProps = oSurface.GetGeneralProperties();
            String propsMsg = "\nGeneral Properties for " + oSurface.Name;
            propsMsg += "\n-------------------";
            propsMsg += "\nMin X: " + genProps.MinimumCoordinateX;
            propsMsg += "\nMin Y: " + genProps.MinimumCoordinateY;
            propsMsg += "\nMin Z: " + genProps.MinimumElevation;
            propsMsg += "\nMax X: " + genProps.MaximumCoordinateX;
            propsMsg += "\nMax Y: " + genProps.MaximumCoordinateY;
            propsMsg += "\nMax Z: " + genProps.MaximumElevation;
            propsMsg += "\nMean Elevation: " + genProps.MeanElevation;
            propsMsg += "\nNumber of Points: " + genProps.NumberOfPoints;
            propsMsg += "\n--";

            editor.WriteMessage(propsMsg);

            // Depending on the surface type, let's look at grid or TIN properties:

            if (oSurface is TinSurface)
            {
                TinSurfaceProperties tinProps = ((TinSurface)oSurface).GetTinProperties();
                propsMsg = "\nTIN Surface Properties for " + oSurface.Name;
                propsMsg += "\n-------------------";
                propsMsg += "\nMin Triangle Area: " + tinProps.MinimumTriangleArea;
                propsMsg += "\nMin Triangle Length: " + tinProps.MinimumTriangleLength;
                propsMsg += "\nMax Triangle Area: " + tinProps.MaximumTriangleArea;
                propsMsg += "\nMax Triangle Length: " + tinProps.MaximumTriangleLength;
                propsMsg += "\nNumber of Triangles: " + tinProps.NumberOfTriangles;
                propsMsg += "\n--";

                editor.WriteMessage(propsMsg);
            }
            else if (oSurface is GridSurface)
            {
                #region GetGridProperties
                GridSurfaceProperties gridProps = ((GridSurface)oSurface).GetGridProperties();
                propsMsg = "\\Grid Surface Properties for " + oSurface.Name;
                propsMsg += "\n-------------------";
                propsMsg += "\n X Spacing: " + gridProps.SpacingX;
                propsMsg += "\n Y Spacing: " + gridProps.SpacingY;
                propsMsg += "\n Orientation: " + gridProps.Orientation;
                propsMsg += "\n--";

                editor.WriteMessage(propsMsg);
                #endregion
            }

        }
        catch (System.Exception e) { editor.WriteMessage(e.Message); }
    }
}

父主题:

曲面

results matching ""

    No results matching ""