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: 

Alignment - Polyline Crossings

24 REPLIES 24
Reply
Message 1 of 25
wally318234MD
1269 Views, 24 Replies

Alignment - Polyline Crossings

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.

24 REPLIES 24
Message 2 of 25
stevenh0616
in reply to: wally318234MD

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

Message 3 of 25
wally318234MD
in reply to: stevenh0616

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.

Message 4 of 25
stevenh0616
in reply to: wally318234MD

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

Message 5 of 25
hosneyalaa
in reply to: wally318234MD

 

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

 

 

Message 6 of 25
wally318234MD
in reply to: hosneyalaa

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?
Message 7 of 25
TerryDotson
in reply to: wally318234MD


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 !!!

Message 8 of 25
hosneyalaa
in reply to: wally318234MD

Hi @wally318234MD 

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

Message 9 of 25
hosneyalaa
in reply to: hosneyalaa

Intersections by Dynamo

 

Q.gif

Message 10 of 25
wally318234MD
in reply to: hosneyalaa

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!

Message 11 of 25
wally318234MD
in reply to: hosneyalaa

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?

Message 12 of 25
hosneyalaa
in reply to: wally318234MD

11.gif

Message 13 of 25
wally318234MD
in reply to: hosneyalaa

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

 

Message 14 of 25
hosneyalaa
in reply to: wally318234MD

I am not sure what is your wrong message

 

But I think it is  

geometry scaling Changing to Large or Extra Large

Message 15 of 25
wally318234MD
in reply to: hosneyalaa

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?

Message 16 of 25
wally318234MD
in reply to: hosneyalaa

It was defaulting to the wrong layer.

Message 17 of 25
Jeff_M
in reply to: wally318234MD

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

Jeff_M, also a frequent Swamper
EESignature
Message 18 of 25
wally318234MD
in reply to: Jeff_M

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. 

Message 19 of 25

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 

Message 20 of 25

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.

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report