public void SelectCrossingDatabase()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed =
doc.Editor;
try
{
PromptPointOptions ptOpts =
new PromptPointOptions(
"\nPick a point at which to select all lines: "
);
PromptPointResult ptRes = ed.GetPoint(ptOpts);
if (PromptStatus.OK == ptRes.Status)
{
ObjectIdCollection ids =
new ObjectIdCollection();
Point3d p = ptRes.Value;
Database db = doc.Database;
Transaction tr =
db.TransactionManager.StartTransaction();
using( tr )
{
BlockTable bt =
(BlockTable)tr.GetObject(
db.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
bt[BlockTableRecord.ModelSpace],
OpenMode.ForRead
);
foreach( ObjectId id in btr )
{
DBObject obj =
tr.GetObject( id, OpenMode.ForRead );
Line dbLine = obj as Line;
if (dbLine != null)
{
LineSegment3d lineSegment =
new LineSegment3d(
dbLine.StartPoint,
dbLine.EndPoint
);
PointOnCurve3d q =
lineSegment.GetClosestPointTo(p);
if (p.DistanceTo( q.Point ) < 0.01)
{
ids.Add( dbLine.ObjectId );
}
}
}
tr.Commit();
}
int n = ids.Count;
ed.WriteMessage(
string.Format(
"\n{0} line{1} selected.",
n, 1 == n ? "" : "s"
)
);
}
}
catch( System.Exception e )
{
ed.WriteMessage("\nException {0}.", e);
}
}
}