0 Members and 1 Guest are viewing this topic.
How to get the curves which is intersect with a selected curve(line or polyline)?
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(); } }