Civil 3D surface elevation analysis

Civil 3d surface analysis is very powerful,

But the analysis style is too free,

Because of too much freedom,

The user experience is not good (personal bias, not necessarily right).

The style in Map3D,

You can use the ribbons of the USGS National Geographic palette,

The result is relatively beautiful,

So came the idea of ​​porting it to Civil 3D,

I wrote part of the code myself,

The results are as follows:

 

 

The code snippet (main code) is as follows:

        public void SetElevationAnalysis()
        {
            string styName = "原始地形高程分析";
            if (!SelectSurface()) return;
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                TinSurface sur = surId.GetObject(OpenMode.ForWrite) as TinSurface;

                double minEle = sur.GetGeneralProperties().MinimumElevation;
                double maxEle = sur.GetGeneralProperties().MaximumElevation;
                sur.Analysis.SetElevationData(CreateElevationAnalysis(minEle, maxEle));
            
                if (GetStyleByName(styName))
                {

                    (_comDoc.ObjectIdToObject(surId.OldIdPtr.ToInt64()) as AeccTinSurface).set_Style(styName);
                }
                sur.Rebuild();
                tr.Commit();
            }
        }

 

The CreateElevationAnalysis method in the above code is as follows:

Used to generate surface elevation analysis data.

 private SurfaceAnalysisElevationData[] CreateElevationAnalysis(double minEle, double maxEle)
        {
            double min = (Math.Floor(minEle / 5)) * 5;
            double max = Math.Ceiling(maxEle);
            double step = Math.Ceiling((max - min) / 22);
            Color[] colors = new Color[]
            {
                Color.FromRgb(116,156,92 ),
                Color.FromRgb(116,172,100),
                Color.FromRgb(148,188,116),
                Color.FromRgb(180,212,116),
                Color.FromRgb(204,228,148),
                Color.FromRgb(220,236,164),
                Color.FromRgb(244,236,164),
                Color.FromRgb(236,220,156),
                Color.FromRgb(244,204,132),
                Color.FromRgb(236,180,132),
                Color.FromRgb(220,156,124),
                Color.FromRgb(196,140,124),
                Color.FromRgb(212,156,148),
                Color.FromRgb(228,172,164),
                Color.FromRgb(220,188,180),
                Color.FromRgb(236,196,212),
                Color.FromRgb(252,204,228),
                Color.FromRgb(252,220,236),
                Color.FromRgb(252,228,224),
                Color.FromRgb(252,220,228),
                Color.FromRgb(252,244,252),
                Color.FromRgb(252,252,252)

            };
            SurfaceAnalysisElevationData[] datas = new SurfaceAnalysisElevationData[22];

            for (int i = 0; i < 22; i++)
            {
                datas[i] = new SurfaceAnalysisElevationData(min + (step * i), min + (step * (i + 1)), colors[i]);
            }

            return datas;
        }

 

The GetStyleByName method is as follows:

Used to get the surface style.

 bool GetStyleByName(string styName)
        {
            var styles = civilDoc.Styles.SurfaceStyles;
            if (!styles.Contains(styName))
            {

                using (Transaction tr = doc.TransactionManager.StartTransaction())
                {
                    ObjectId id = styles.Add(styName);
                    SurfaceStyle sty = id.GetObject(OpenMode.ForWrite) as SurfaceStyle;
                    sty.CreateBy = "\u738B\u78CA";
                    if (styName.Contains("高程") || styName.Contains("高度"))
                    {
                        sty.GetDisplayStylePlan(SurfaceDisplayStyleType.Elevations).Visible = true;
                        sty.GetDisplayStyleModel(SurfaceDisplayStyleType.Elevations).Visible = true;
                    }
                    if (styName.Contains("坡度"))
                    {
                        sty.GetDisplayStylePlan(SurfaceDisplayStyleType.Slopes).Visible = true;
                        sty.GetDisplayStyleModel(SurfaceDisplayStyleType.Slopes).Visible = true;
                    }
                    tr.Commit();
                }
            }
            return (civilDoc.Styles.SurfaceStyles.Contains(styName));
        }
The SelectSurface () method is used to obtain the surId. 
You can complete it by yourself .
_ComDoc is a com document, which is
used to set the surface style.
.Netapi is incomplete, and you
have to use the com api to achieve
this part of the content. The content of the relevant chapters in Development.

With the above code, I
believe you can quickly
set up the analysis style of Civil 3D surface without overflowing your own commands .

 

Guess you like

Origin www.cnblogs.com/myzw/p/12744731.html