.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting an intersecting point coordinate of two polylines(lines)

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
dynamicscope
6606 Views, 6 Replies

Getting an intersecting point coordinate of two polylines(lines)

Hi, I wonder if there is a way to get an intersecting point coordinate of two polylines(lines) programmatically.

For example, like in the below sample picture, I need to get coordinates of the points in the red cycles.

 

sample.PNG

 

 

Is there any method that I can easily use?

Could I get a sample code snippet that computes the coordinates? (in C# & ObjectARX 2010 if possible?)

 

I've looked up "Through the Interface" and this disscussion group. couldn't find any useful yet.

Please someone help me. =(

 

 

Thank you for your time.

 

Jake

6 REPLIES 6
Message 2 of 7
Hallex
in reply to: dynamicscope

Check this out

 

        [CommandMethod("checkinters")]
        public void CheckInterference()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
    
                Transaction tr = db.TransactionManager.StartTransaction();

                using (tr)
                {
                    try
                    {
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                        PromptEntityOptions peo = new PromptEntityOptions("\nSelect a first polyline  >>");

                        peo.SetRejectMessage("\nSelected object might be of type polyline only >>");

                        peo.AddAllowedClass(typeof(Polyline), false);

                        PromptEntityResult res;

                        res = ed.GetEntity(peo);

                        if (res.Status != PromptStatus.OK)

                            return;

                        Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);

                        if (ent == null)

                            return;

                        Polyline poly = (Polyline)ent as Polyline;
                        peo = new PromptEntityOptions("\nSelect second polyline  >>");

                        peo.SetRejectMessage("\nSelected object might be of type polyline only >>");

                        peo.AddAllowedClass(typeof(Polyline), false);

                        res = ed.GetEntity(peo);

                        if (res.Status != PromptStatus.OK)

                            return;

                        ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);

                        if (ent == null)

                            return;

                        Polyline poly2 = (Polyline)ent as Polyline;


                        Point3dCollection pts = new Point3dCollection();

                        poly.IntersectWith(poly2, Intersect.OnBothOperands, pts, (int)IntPtr.Zero, (int)IntPtr.Zero);

                        Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("Hint:\nNumber of Verices: {0}\nNumber of Intersections: {1}", poly.NumberOfVertices, pts.Count));
                     // test for visulization only
                        foreach (Point3d pt in pts)
                        {
                            Circle circ = new Circle(pt,Vector3d.ZAxis,10 * db.Dimtxt);
                            circ.ColorIndex = 1;
                            btr.AppendEntity(circ);
                            tr.AddNewlyCreatedDBObject(circ, true);

                        }
                        tr.Commit();
                    }
                    catch (System.Exception ex)
                    {
                        ed.WriteMessage("\n{0}\n{1}", ex.Message, ex.StackTrace);
                    }
                }

            }

 

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 7
Hallex
in reply to: dynamicscope

Can you upload the piece of this drawing

for testing?

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 7
dynamicscope
in reply to: Hallex

It does work!! Thank you!! 😃

Message 5 of 7
Hallex
in reply to: dynamicscope

You're welcome

Happy coding Smiley Happy

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 7
applie_3
in reply to: dynamicscope

Hi, i need to get coordinates of an image in autocad for my final year project. I am a student of computer engineering so dont have autocad background. Any help will highly be appriciated, thankyou.

Message 7 of 7
amitnkukanur
in reply to: Hallex

Hello,

 

After long time i am back to customization.

 

In this above code, rather than user selecting polylines, can't we use select all option to check interferece.

if yes what are the changes to be made to the above code.

 

Regards,

Amit

 

 

Senior Software Engineer

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost