Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Alignment - Polyline Crossings

wally318234MD
Contributor

Alignment - Polyline Crossings

wally318234MD
Contributor
Contributor

I would like a routine of some sort to either produce stationing in M-Text or a report for 2d polyline crossings of an alignment. If possible, I would like for this routine to be able to pick up the stationing of the intersections plus any object data associated with the polylines.

0 Likes
Reply
1,655 Views
24 Replies
Replies (24)

stevenh0616
Collaborator
Collaborator

Hi @wally318234MD,

 

This is certainly all possible with the APIs.

 

You would prompt the user to select an alignment or multiple alignments and automatically select all Polylines (there are 3 types). You may want control over the polyline layers to reduce the selection set.

 

From there, you can make an ExtensionMethod similar to what's shown here that iterates through the segments of the alignment and checks for intersection with the polylines. You may need to loop through those polyline segments as well.

https://adndevblog.typepad.com/infrastructure/2014/10/alignment-sample-line-intersection.html

 

The extension method should return the Intersection point for a specific polyline.

 

From that Point, you can use Alignment.StationOffset(easting, northing, ref Station, ref Offset). This will return the station value. You can format it like this

https://adndevblog.typepad.com/infrastructure/2015/03/formatting-stations-with-net-extension.html

 

Then you'd just have to extract whatever info about each crossing Polyline you're looking for.

 

 

Does this help?

Steve Hill, Civil Designer / .NET Developer / AutoCAD and AutoCAD Civil 3D Certified Professional
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

http://redtransitconsultants.com/
Autodesk Exchange Store
Twitter | LinkedIn | YouTube

0 Likes

wally318234MD
Contributor
Contributor

This sounds great, but I think it's a little beyond my capabilities. I'm just a lowly Designer. I wouldn't be sure where to start with the programming part of this. That being said, I love learning new things and think it would definitely benefit me to learn the VBA procedures.

0 Likes

stevenh0616
Collaborator
Collaborator

I see. I thought you were looking for answers on how you'd do this in the API.

 

The same process could likely be done in dynamo but it would similar on how you'd build this out from a programming standpoint. It's supposed to be a bit easier to build out a custom application.

 

Either way, there's a decent amount of work here to build this. You can reach out to me through my website, or you can find other developers through the Autodesk App Store or through Autodesk Customer Success

Steve Hill, Civil Designer / .NET Developer / AutoCAD and AutoCAD Civil 3D Certified Professional
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

http://redtransitconsultants.com/
Autodesk Exchange Store
Twitter | LinkedIn | YouTube

0 Likes

hosneyalaa
Advisor
Advisor

 

HI @wally318234MD 

CAN YOU USING CODE WITH SOME CHINGE 

//https://forums.autodesk.com/t5/civil-3d-customization/split-corridor-using-c/m-p/10287395

[CommandMethod("SpitCorridor")]
        public void SpitCorridor()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            List<Polyline> polylines = new List<Polyline>();
            TypedValue[] _tv = new TypedValue[1] { new TypedValue((int)DxfCode.Start, "LWPOLYLINE")};
            SelectionFilter _ts = new SelectionFilter(_tv);

            PromptSelectionOptions _op = new PromptSelectionOptions();
            _op.MessageForAdding = "Select Polylines";
            PromptSelectionResult _ops = ed.GetSelection(_op, _ts);

            if (_ops.Status != PromptStatus.OK)
                return;

            var options = new PromptEntityOptions("\nSelect Corrior: ");
            options.SetRejectMessage("Must be corridor.");
            options.AddAllowedClass(typeof(Corridor), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK)
                return;
            var cor = result.ObjectId;
            using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in _ops.Value.GetObjectIds())
                {
                    Polyline polyline = tr.GetObject(id, OpenMode.ForRead) as Polyline;
                    polylines.Add(polyline);
                    Corridor corridor = (Corridor)tr.GetObject(cor, OpenMode.ForRead);
                    CheckGiaocat(corridor, polylines);
                }    
            }    
        }
        public void CheckGiaocat(Corridor corridor, List<Polyline> polylines)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
            {
                List<Alignment> alignments = new List<Alignment>();
                List<double> lststation = new List<double>();
                foreach (Baseline ba in corridor.Baselines)
                {
                    Alignment oAlign = tr.GetObject(ba.AlignmentId, OpenMode.ForRead) as Alignment;
                    if(oAlign.AlignmentType==AlignmentType.Centerline)
                    {
                        alignments.Add(oAlign);
                    }    
                }
                
                foreach (Polyline pl in polylines)
                {
                    Point3dCollection p3dCollection = new Point3dCollection();
                    foreach (var al in alignments)
                    {
                        pl.IntersectWith(al, Intersect.OnBothOperands, p3dCollection, IntPtr.Zero, IntPtr.Zero);
                        foreach (Point3d pt in p3dCollection)
                        {
                            var stt=al.GetClosestPointTo(pt,false);
                            var station = al.GetDistAtPoint(pt);
                            if (!lststation.Contains(station))
                            {
                                lststation.Add(station);
                            }

                            foreach (Baseline ba in corridor.Baselines)
                            {
                                if (ba.AlignmentId == al.ObjectId)
                                {
                                    BaselineRegionCollection baselineRegions = ba.BaselineRegions;
                                    foreach (double station1 in lststation)
                                    {
                                        ed.WriteMessage("Lý trình là:" + station1);
                                        foreach (BaselineRegion baselineRegion in baselineRegions)
                                        {
                                            if ((station1 < baselineRegion.StartStation ? false : station1 <= baselineRegion.EndStation))
                                            {
                                                try
                                                {
                                                    baselineRegion.AddStation(station1, "A");
                                                    baselineRegion.Split(station1);
                                                    corridor.Rebuild();
                                                }
                                                catch
                                                {
                                                    continue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }                               
                    }    
                }
                tr.Commit();
            }    
        }

 

 

0 Likes

wally318234MD
Contributor
Contributor
Thank you for this routine. I'm not able to rewrite these, but I did try to put it in my Civil as a lisp with no luck. Is it not a lisp routine?
0 Likes

TerryDotson
Mentor
Mentor

Thank you for this routine. I'm not able to rewrite these, but I did try to put it in my Civil as a lisp with no luck. Is it not a lisp routine?

That is not a Lisp routine, it is .NET code, in the C# language and it must be compiled before it will run inside Civil3D.  You could obtain the Visual Studio Community edition at no charge from Microsoft and compile it yourself.  However, without prior knowledge of the process you are looking at a learning curve of at least a couple hours.  However, it would not be wasted time, as you could benefit from samples provided and potentially learn to create your own code over time.  Then problems you might encounter become a mere speed bump !!!

hosneyalaa
Advisor
Advisor

Hi @wally318234MD 

if You have Civil 3D 2021 and up You can use the dynamo

0 Likes

hosneyalaa
Advisor
Advisor

Intersections by Dynamo

 

Q.gif

wally318234MD
Contributor
Contributor

This is awesome! I am currently going through some training videos to learn how to operate Dynamo. Thank you so much for steering me in the right direction!

0 Likes

wally318234MD
Contributor
Contributor

wally318234MD_0-1668032234522.png

I do have a question though. What is in the code block box here and what is the box behind it?

0 Likes

hosneyalaa
Advisor
Advisor

11.gif

0 Likes

wally318234MD
Contributor
Contributor

Thank you for clearing that up for me! The alignment that I'm using for this routine does not have curves in it and I can't figure out how to get this part to work. 

wally318234MD_0-1668113687435.png

 

0 Likes

hosneyalaa
Advisor
Advisor

I am not sure what is your wrong message

 

But I think it is  

geometry scaling Changing to Large or Extra Large

0 Likes

wally318234MD
Contributor
Contributor

I set it to extra large and still not working. Might it be because it's trying to get curves from an alignment that doesn't have curves?

0 Likes

wally318234MD
Contributor
Contributor

It was defaulting to the wrong layer.

0 Likes

Jeff_M
Consultant
Consultant

@wally318234MD All alignment entities are derived from the AutoCAD Curve object...Arcs, Tangents, Spirals are all Curves.

Jeff_M, also a frequent Swamper
EESignature
0 Likes

wally318234MD
Contributor
Contributor

Thank you Jeff. I noticed that by counting all the segments of the alignment that I'm using and comparing that to the number of curves in Dynamo. 

0 Likes

maalkhamRT6W2
Explorer
Explorer

Hi   I have created alignment Route and I had multiple existing crossing as polylins objects crossing my alignment route along my long route ,questions do you have way in civil 3d can automating Idetifying the crossings locations and creating the crossings as report giving stationing and coordinates location for all crossing points against my alignment route ?....Regards 

0 Likes

wally318234MD
Contributor
Contributor
That's what I'm trying to figure out. I've had to take a break from it for now due to heavy work load.
0 Likes