Surface Properties .NET API

Surface Properties .NET API

artillis_prado
Enthusiast Enthusiast
1,011 Views
2 Replies
Message 1 of 3

Surface Properties .NET API

artillis_prado
Enthusiast
Enthusiast

I am using the file intro-1.dwg. I am trying to change the following settings:

  1. Analysis Type:

    • Change from "Elevations" to "Slopes".
  2. Ranges:

    • Set the "Number" to 2.
  3. Run the analysis.

 

artillis_prado_0-1718217291003.png

 

 

            Document acDoc = AutoCadApp.DocumentManager.MdiActiveDocument;

            using (acDoc.LockDocument())
            using (Database acDb = acDoc.Database)
            using (Transaction acT = acDb.TransactionManager.StartTransaction())
            {
                CivilDocument civilDocument = CivilDocument.GetCivilDocument(acDoc.Database);

                BlockTable bT = acDb.GetBlockTable(acT);

                BlockTableRecord modelSpace = acDb.GetModelSpace(acT);

                Editor ed = acDoc.Editor;

                // Select a Tin Surface
                PromptEntityOptions peo = new PromptEntityOptions(
                  "\nSelect a tin surface: ");
                peo.SetRejectMessage("\nOnly Tin surface is accepted");
                peo.AddAllowedClass(typeof(TinSurface), true);
                PromptEntityResult per = ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK) return;

                CivilDocument civilDoc = CivilApplication.ActiveDocument;

                TinSurface surface = acT.GetObject(per.ObjectId, OpenMode.ForRead) as TinSurface;

                ObjectId styleId;
                styleId = civilDoc.Styles.SurfaceStyles["Slope Banding (2D)"];

                var value = surface.StyleId;

                SurfaceAnalysis surfaceAnalysis = surface.Analysis;

                surface.StyleId = styleId;

                acT.Commit();

                surface.Rebuild();
            }

 

 

0 Likes
Accepted solutions (1)
1,012 Views
2 Replies
Replies (2)
Message 2 of 3

Jeff_M
Consultant
Consultant
Accepted solution

Add this to your code:

                SurfaceAnalysis surfaceAnalysis = surface.Analysis;

                var data = new List<SurfaceAnalysisSlopeData>();
                data.Add(new SurfaceAnalysisSlopeData(0, 0.05, Color.FromColorIndex(ColorMethod.ByAci,(short)1) ));
                data.Add(new SurfaceAnalysisSlopeData(0.05, 0.20, Color.FromColorIndex(ColorMethod.ByAci, (short)2)));
                surfaceAnalysis.SetSlopeData(data.ToArray());
                surface.Rebuild();
                dynamic surf = surface.AcadObject;
                surf.Update();//without this a Regen is required
                acT.Commit();

This adds 2 regions, 0 - 5% & 5% - 20%, with the colors Red and Yellow.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 3

artillis_prado
Enthusiast
Enthusiast
It worked, thank you very much @Jeff_M .
0 Likes