static double RoundToRowHeight(double d, double rowHeight)
{
return Math.Round(d / rowHeight) * rowHeight;
}
static Point3d TextPosition(DBText txt)
{
return txt.Justify == AttachmentPoint.BaseLeft ?
txt.Position : txt.AlignmentPoint;
}
static string[][] GroupTextsByRow(SelectionSet selection, double rowHeight)
{
using (var tr
= new OpenCloseTransaction
()) {
return selection.GetObjectIds()
.Where(id => id.ObjectClass.DxfName == "TEXT")
.Select(id => (DBText)tr.GetObject(id, OpenMode.ForRead))
.GroupBy(txt => RoundToRowHeight(TextPosition(txt).Y, rowHeight))
.OrderByDescending(grp => grp.Key)
.Select(grp => grp.OrderBy(txt => TextPosition(txt).X)
.Select(txt => txt.TextString)
.ToArray())
.ToArray();
}
}