Here is something to play with ..
//
// CodeHimBelonga KDUB 2011.11.19.
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof (KDUB.IntersectExample.IntersectionTest))]
namespace KDUB.IntersectExample
{
public class IntersectionTest
{
[CommandMethod("Test", CommandFlags.Modal)]
public void IntersectionTest01() {
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Point3d IntersectionPoint;
using (Transaction tr = db.TransactionManager.StartTransaction()) {
ObjectId id1 = SelectSpecificObjectType("\nSelect Line entity: ",
typeof (Line));
if (id1.IsNull) {
return;
}
ObjectId id2 = SelectSpecificObjectType("\nSelect next Line entity: ",
typeof (Line));
if (id2.IsNull) {
return;
}
Line line1 = (Line) tr.GetObject(id1, OpenMode.ForRead);
Line line2 = (Line) tr.GetObject(id2, OpenMode.ForRead);
IntersectionPoint = lineIntersectors(line1.StartPoint,
line1.EndPoint, line2.StartPoint,
line2.EndPoint);
tr.Commit();
}
AcadApp.ShowAlertDialog(string.Format("X: {0} \nY: {1} \nZ: {2} \n",
IntersectionPoint.X, IntersectionPoint.Y,
IntersectionPoint.Z));
}
private static Point3d lineIntersectors(Point3d spt1, Point3d ept1, Point3d spt2,
Point3d ept2) {
using (Line3d line1 = new Line3d(spt1, ept1),
line2 = new Line3d(spt2, ept2)) {
return line1.IntersectWith(line2)[0];
}
}
private static ObjectId SelectSpecificObjectType(string prompt,
System.Type objectClass) {
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
using (
Transaction tr =
ed.Document.Database.TransactionManager.StartTransaction()) {
while (true) {
PromptEntityResult res = ed.GetEntity(prompt);
if (res.Status != PromptStatus.OK) {
return ObjectId.Null;
}
DBObject ob = tr.GetObject(res.ObjectId, OpenMode.ForRead);
if (objectClass.IsAssignableFrom(ob.GetType())) {
return res.ObjectId;
}
ed.WriteMessage("\nInvalid selection, {0} entity expected",
RXClass.GetClass(objectClass).DxfName);
}
}
}
}
}
And a piccy
and the source solution zipped