Community
Hi All,
I need to get the type of entities which intersect with a specific polyline.
Exactly i need to know if the type is (Block Reference) or no.
Please help me
Thanks in advance.
Solved! Go to Solution.
Solved by SENL1362. Go to Solution.
This sample may help:
[CommandMethod("TestIntersectPolyline")] public void TestIntersectPolyline() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; try { PromptEntityOptions peo = new PromptEntityOptions("Select Polyline"); peo.AllowNone = true; PromptEntityResult per = null; do { per = ed.GetEntity(peo); if (per.Status == PromptStatus.Cancel) return; } while (per.Status != PromptStatus.OK && per.ObjectId.ObjectClass.DxfName != "LWPOLYLINE"); ObjectId polyId = per.ObjectId; using (Transaction tr = db.TransactionManager.StartTransaction()) { Polyline poly = (Polyline)tr.GetObject(polyId, OpenMode.ForRead); //polySpace could be any Block: ms, ps or blocks BlockTableRecord polySpace = (BlockTableRecord)tr.GetObject(poly.BlockId, OpenMode.ForRead); foreach (ObjectId entId in polySpace) { //remove next 2 lines to test intersection with all kind of entities if (entId.ObjectClass.DxfName != "INSERT") continue; Entity ent = (Entity)tr.GetObject(entId, OpenMode.ForRead); //quick test based on extents if (ent.GeometricExtents.MinPoint.X > ent.GeometricExtents.MaxPoint.X) continue; //Ent left from Poly if (ent.GeometricExtents.MinPoint.Y > ent.GeometricExtents.MaxPoint.Y) continue; //Ent above from Poly if (ent.GeometricExtents.MaxPoint.X < ent.GeometricExtents.MinPoint.X) continue; //Ent right from Poly if (ent.GeometricExtents.MaxPoint.Y < ent.GeometricExtents.MinPoint.Y) continue; //Ent below from Poly Point3dCollection intersections = new Point3dCollection(); poly.IntersectWith(ent, Intersect.OnBothOperands, intersections, IntPtr.Zero, IntPtr.Zero); if (intersections != null && intersections.Count > 0) { switch (entId.ObjectClass.DxfName) { case "INSERT": BlockReference blkRef = (BlockReference)ent; ed.WriteMessage("\n Insert: {0} intersect with Poly", blkRef.Name); break; default: ed.WriteMessage("\n {0}: {1} intersect with Poly", entId.ObjectClass.DxfName, ent.Handle); break; } } } tr.Commit(); } } catch (System.Exception ex) { ed.WriteMessage(ex.Message); } }
Hi,
Another idea, use the polyline coordinates in a fence selection.
Gaston Nunez