Getting Material quantities using C#

Getting Material quantities using C#

Anonymous
Not applicable
1,862 Views
3 Replies
Message 1 of 4

Getting Material quantities using C#

Anonymous
Not applicable

I am writing a C# program to read material quantities from a Civil 3D model. I can get cut/fill areas at a sampleline but have not been able to get structural material quantities (e.g., pavement, base, subbase material areas at a sampleline or section). Any help will be appreciated.

Thanks.

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

michael_robertson
Collaborator
Collaborator
Accepted solution

Strange coincidence, I just started working on something similar yesterday. I'm trying to see if there is a way to get the final volume and location of objects created in a corridor programmatically. For example, I need to get the begin/end station of a lane and it's final volume.

 

Not sure if I'll need to keep track of shapes areas at each frequency and use end area calculations or if I can get the final volume from the model.

 

Here's the code to go through the corridor and read SA areas:

        public void CorridorShapes()
        {
            Document acadDocument = Application.DocumentManager.MdiActiveDocument;
            Database database = acadDocument.Database;
            Autodesk.Civil.ApplicationServices.CivilDocument civilDocument = Autodesk.Civil.ApplicationServices.CivilDocument.GetCivilDocument(database);

            CorridorCollection corridorCollection = civilDocument.CorridorCollection;

            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {
                foreach (ObjectId corridorId in corridorCollection)
                {
                    Corridor corridor = (Corridor)transaction.GetObject(corridorId, OpenMode.ForRead);
                    BaselineCollection baselines = corridor.Baselines;

                    foreach (Baseline baseline in baselines)
                    {
                        ObjectId algnId = baseline.AlignmentId;
                        BaselineRegionCollection baselineRegions = baseline.BaselineRegions;
                        foreach (BaselineRegion baselineRegion in baselineRegions)
                        {
                            AppliedAssemblyCollection appliedAssemblies = baselineRegion.AppliedAssemblies;
                            double[] appliedStations = appliedAssemblies.Stations();
                            List<double> stationList = appliedStations.ToList();
                            stationList.Sort();

                            foreach (double station in stationList)
                            {
                                AppliedAssembly appliedAssembly = appliedAssemblies.GetItemAt(station);
                                Assembly assembly = (Assembly)transaction.GetObject(appliedAssembly.AssemblyId, OpenMode.ForRead);

                                AppliedSubassemblyCollection appliedSubassemblies = appliedAssembly.GetAppliedSubassemblies();
                                foreach (AppliedSubassembly appliedSubassembly in appliedSubassemblies)
                                {
                                    Subassembly subassembly = (Subassembly)transaction.GetObject(appliedSubassembly.SubassemblyId, OpenMode.ForRead);
                                    CalculatedShapeCollection calculatedShapes = appliedAssembly.Shapes;
                                }
                            }
                        }
                    }
                }
            }
        }

 

The code is from this post: Corridor Solids trough API - Autodesk Community - Civil 3D 

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
0 Likes
Message 3 of 4

Anonymous
Not applicable
Accepted solution

Thank you for the quick response. I don't have an answer for your question at this time. Let me experiment with the code you sent me and respond when I have a good solution.

Stay safe.

0 Likes
Message 4 of 4

michael_robertson
Collaborator
Collaborator

Found what seems to be the easiest option is to export the corridor to solids makes it pretty easy. All the corridor property set data comes across to the solid such as Baseline info, stations, etc. If you create the solids with the "Dynamic link to corridor" option enabled  (on the output options) the solids update automatically when the corridor changes and is rebuilt.

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
0 Likes