Author Topic: How to get the curves which is intersect with a selected curve?  (Read 1807 times)

0 Members and 1 Guest are viewing this topic.

csharpbird

  • Newt
  • Posts: 64
How to get the curves which is intersect with a selected curve?
« on: November 09, 2009, 11:31:03 PM »
How to get the curves which is intersect with a selected curve(line or polyline)?

Bryco

  • Water Moccasin
  • Posts: 1883
Re: How to get the curves which is intersect with a selected curve?
« Reply #1 on: November 10, 2009, 10:14:34 AM »
use a selectionset to get the curves and use a foreach to check for a count of more than zero intersection points.

fixo

  • Guest
Re: How to get the curves which is intersect with a selected curve?
« Reply #2 on: November 10, 2009, 01:40:37 PM »
How to get the curves which is intersect with a selected curve(line or polyline)?
Give this a shot

Code: [Select]
        public static void CurveCurveIntersection()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptSelectionOptions pso = new PromptSelectionOptions();
            pso.SingleOnly = true;
            pso.MessageForRemoval = "\nMust be a polyline only: ";
            pso.MessageForAdding = "\nSelect single polyline: ";
            PromptSelectionResult res = ed.GetSelection(
                pso,
                new SelectionFilter
                (new TypedValue[] { new TypedValue(0, "LWPOLYLINE") })
                );

            ObjectId[] ids = res.Value.GetObjectIds();
            ObjectId idx = ids[0];

            PromptSelectionResult pres = ed.SelectAll(new SelectionFilter
                (new TypedValue[] { new TypedValue(0, "LWPOLYLINE") })
                );
            ObjectId[] ipds = pres.Value.GetObjectIds();
            ObjectIdCollection ixs = new ObjectIdCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Polyline pline = (Polyline)tr.GetObject(idx, OpenMode.ForRead);
                foreach (ObjectId i in ipds)
                {
                    Entity ent = (Entity)tr.GetObject(i, OpenMode.ForRead);
                    Polyline intpline = ent as Polyline;
                    if (intpline != null)
                    {
                        Point3dCollection iwpnts = new Point3dCollection();
                        intpline.IntersectWith(pline,
Intersect.OnBothOperands, iwpnts, 0, 0);
                        if ((iwpnts.Count > 0) && (i!=idx))
                        {
                            foreach (Point3d pt in iwpnts)
                                ed.WriteMessage("\nIntersection at point: {0}" , pt);
                            ixs.Add(i);
                        }
                    }
                }
                if (ixs.Count > 0)
                {
                    ed.WriteMessage("\nIntersect with {0} polylines", ixs.Count);
                    foreach (ObjectId j in ixs)
                    {
                        ed.WriteMessage("\nObjectID = {0}", j);
                    }
                }
                tr.Commit();
            }
        }

~'J'~