TheSwamp
Code Red => .NET => Topic started by: csharpbird on November 09, 2009, 11:31:03 PM
-
How to get the curves which is intersect with a selected curve(line or polyline)?
-
use a selectionset to get the curves and use a foreach to check for a count of more than zero intersection points.
-
How to get the curves which is intersect with a selected curve(line or polyline)?
Give this a shot
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'~