Ejemplo n.º 1
0
        getAverageElev(ObjectId idPoly, bool boolShowPoints, string strSurface)
        {
            double dblZ_Total = 0;
            double dblZ_AVG   = 0;

            bool       exists         = false;
            ObjectId   idSurfaceEXIST = Surf.getSurface(strSurface, out exists);
            TinSurface surfaceEXIST   = (TinSurface)idSurfaceEXIST.getEnt();

            if (surfaceEXIST.GetGeneralProperties().MinimumElevation <= 0.0)
            {
                Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog(string.Format("Check Surface EXIST elevations: Minimum elevation: {0}", surfaceEXIST.GetGeneralProperties().MinimumElevation));
                return(0);
            }

            using (BaseObjs._acadDoc.LockDocument())
            {
                if (!idPoly.isRightHand())
                {
                    idPoly.reversePolyX();
                }
                idPoly.checkIfClosed();
            }

            Point3dCollection pntsGrid     = Misc.getBldgLimitsAVG(idPoly, 20);
            Point3dCollection pntsGridElev = new Point3dCollection();

            foreach (Point3d pnt3d in pntsGrid)
            {
                try
                {
                    double dblZ = surfaceEXIST.FindElevationAtXY(pnt3d.X, pnt3d.Y);
                    dblZ_Total = dblZ_Total + dblZ;

                    if (boolShowPoints)
                    {
                        pntsGridElev.Add(new Point3d(pnt3d.X, pnt3d.Y, dblZ));
                    }
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(ex.Message + " Grading_Floor.cs: line: 115");
                }
            }

            if (boolShowPoints)
            {
                uint pntNum;

                using (BaseObjs._acadDoc.LockDocument())
                {
                    foreach (Point3d pnt3d in pntsGridElev)
                    {
                        pnt3d.setPoint(out pntNum, "CPNT-ON");
                    }
                }
            }

            dblZ_AVG = dblZ_Total / (pntsGrid.Count);

            return(dblZ_AVG);
        }