Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Surface Properties .NET API

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
artillis_prado
327 Views, 2 Replies

Surface Properties .NET API

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();
            }

 

 

2 REPLIES 2
Message 2 of 3
Jeff_M
in reply to: artillis_prado

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
in reply to: Jeff_M

It worked, thank you very much @Jeff_M .

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report