never used this code by myself but you can use GetCloseestPointTo Method
line.GetClosestPointTo (pickedPt.TransformBy (ed.CurrentUserCoordinateSystem), false);
Here general logic, i am assuming that you already have two lines on your active drawing. User will select two lines one by one. You'll have two line object plus selected points, you can just calculate closes point using GetCloseestPointTo method. here is sample code, I've tested it it's working fine
[CommandMethod("Test")]
public static void Test()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var entOpts = new PromptEntityOptions("\nSelect the first line: ");
entOpts.SetRejectMessage("\nSelected object is not a line.");
entOpts.AddAllowedClass(typeof(Line), true);
var entRes = ed.GetEntity(entOpts);
if (entRes.Status != PromptStatus.OK)
return;
var line1Id = entRes.ObjectId;
var pickedPt = entRes.PickedPoint;
entOpts.Message = "\nSelect the second line: ";
entRes = ed.GetEntity(entOpts);
if (entRes.Status != PromptStatus.OK)
return;
var line2Id = entRes.ObjectId;
using (var tr = db.TransactionManager.StartTransaction())
{
var line1 = (Line)tr.GetObject(line1Id, OpenMode.ForRead);
var line2 = (Line)tr.GetObject(line2Id, OpenMode.ForRead);
var pt1 = line1.GetClosestPointTo(pickedPt.TransformBy(ed.CurrentUserCoordinateSystem), false);
var pt2 = line2.GetClosestPointTo(pt1, true);
var dim = new AlignedDimension(pt1, pt2, pt1, null, db.Dimstyle);
var space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
space.AppendEntity(dim);
tr.AddNewlyCreatedDBObject(dim, true);
tr.Commit();
}
}
YOu'll have 2 points, you can add align dim or Just calculate distance between pt1 and pt2 and display it wherever you want