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: 

Extract triangles from Corridor Surface

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
prosterian
311 Views, 2 Replies

Extract triangles from Corridor Surface

Hi everyone!

I wanna get a Triangles collection from Corridor design surface as I do from TINSurface like:

 

 

TinSufaceTriangleCollection triangles = surface.Triangles;

 

 

I have a Railroad line and a corridor based on design profile of that line and earth surface. I've used a very simple section construction assembled from elements of a base construction library. 

RR_Corridor_1.png

 

RR_Corridor_2.png

As I can see my corridor literally have a suface and triangulation in it.

No matter how hard i've tried I didn't find a way to get this triangles. The most obvious for me was to get surfaces from corridor like:

 

 

CorridorSurfaceCollection corSfcs = corridor.CorridorSurfaces;

 

 

But there's two problems. First of all value returned by CorridorSurfaces property never have a surfaces inside. I mean the array is always empty. But even if it would contain a surface it will be CorridorSurface Type which have no property or method that will return triangle collection. Maybe I can use CorridorSurface.SurfaceId in which i'll get what i want but at first I need to get CorridorSurface.

I'm some kind of confused. Maybe I should create a surface some another way or smth? Can somebody point on where I'm going wrong way?

Regards!

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

If there is a corridor surface it will be listed in the CorridorSurfaces property. Here is an example which works using the tutorial Corridor - 5c.dwg. 

Command: CORRIDORSURFACETEST
There are 4 surface defined in corridor Corridor - (1)
There are 3352 visible triangles in surface Corridor - (1) Top.

2022-01-21_11-30-34.png

 

        [CommandMethod("CorridorSurfaceTest")]
        public void surftest()
        {
            string corridorSurfaceName = "Corridor - (1) Top";
            string corridorName = "Corridor - (1)";
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var _civilDoc = CivilApplication.ActiveDocument;
            // get the CorridorSurface by name:
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                ObjectId corridorId = _civilDoc.CorridorCollection[corridorName];
                Corridor corridor = tr.GetObject(corridorId, OpenMode.ForRead) as Corridor;
                CorridorSurface corridorSurface = corridor.CorridorSurfaces[corridorSurfaceName];
                TinSurface tinsurf = (TinSurface)tr.GetObject(corridorSurface.SurfaceId, OpenMode.ForRead);
                var triangles = tinsurf.GetTriangles(false);
                ed.WriteMessage("\nThere are {0} surface defined in corridor {1}", corridor.CorridorSurfaces.Count, corridorName);
                ed.WriteMessage("\nThere are {0} visible triangles in surface {1}.", triangles.Count.ToString(), corridorSurfaceName);
                tr.Commit();
            }
        }
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 3
prosterian
in reply to: Jeff_M

Thanks a lot! That's exactly what I was looking for. I've created the corridor but didn't add a surfaces in corridor properties dialog. Now everything's fine! 😊

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report