Deep inside the code see SegmentType:
[CommandMethod("lotes")]
public static void GenerateCoordTable()
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
try
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a boundary polygon >>");
peo.SetRejectMessage("\nSelect Polyline only >>");
peo.AddAllowedClass(typeof(Polyline), false);
PromptEntityResult res;
res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK)
return;
Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
if (ent == null)
return;
Polyline poly = (Polyline)ent as Polyline;
if (poly == null)
return;
string lotno = UserInteraction.UserInput.GetStringDefault(ed, "\nEnter a lot number", "101");
int prec;
if (!(UserInteraction.UserInput.GetIntDefault(ed, "\nEnter number of decimals for table values: ", 1, out prec)))
{
ed.WriteMessage("\nNo value entered. Programm exiting");
return;
}
double hgt = UserInteraction.UserInput.GetRealDefault(ed, "\nEnter text height for data cells: ", 0.2);
List<string[]> arr = PointsToTable(poly, prec);
if (arr == null)
return;
Point3d position = new Point3d();
if (!(UserInteraction.UserInput.GetFirstPoint(ed, "Specify insertion point: ", out position)))
{
ed.WriteMessage("\nNo points picked. Programm exiting");
return;
}
//draw table
int nmRows = arr.Count + 2;
int nmColumns = arr[0].Length;
double rowHeight = hgt * 1.5;
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
Table oTable = new Table();
oTable.IsHeaderSuppressed = false;
oTable.IsTitleSuppressed = false;
oTable.VerticalCellMargin = hgt * 0.1;
oTable.HorizontalCellMargin = hgt * 0.1;
oTable.NumColumns = nmColumns;
oTable.NumRows = nmRows;
oTable.Height = nmRows * hgt * 1.25;
oTable.Width = hgt * 76;
oTable.Position = position;
oTable.SuppressRegenerateTable(true);
oTable.GenerateLayout();
oTable.SetTextString(0, 0, "Lotes " + lotno.ToString());
SetCell(oTable, 0, 0, "Lotes " + lotno.ToString(), hgt * 2.0, CellAlignment.MiddleCenter);
oTable.SetColumnWidth(0, hgt * 16);
oTable.SetColumnWidth(1, hgt * 15);
oTable.SetColumnWidth(2, hgt * 15);
oTable.SetColumnWidth(3, hgt * 15);
oTable.SetColumnWidth(4, hgt * 15);
oTable.SetTextHeight(hgt * 2, (int)RowType.TitleRow);
oTable.SetTextHeight(hgt * 1.5, (int)RowType.HeaderRow);
oTable.SetTextHeight(hgt, (int)RowType.DataRow);
string[] hdl = new string[5];
hdl[0] = "Point No";
hdl[1] = "X";
hdl[2] = "Y";
hdl[3] = "Z";
hdl[4] = "Radius";
for (int i = 0; i < hdl.Length; i++)
{
string s = hdl[i];
SetCell(oTable, 1, i, s, hgt * 1.5, CellAlignment.MiddleCenter);
}
for (int i = 0; i < arr.Count; i++)
{
string[] line = arr[i];
for (int j = 0; j < hdl.Length; j++)
{
string s = line[j];
ed.WriteMessage("\n\t{0}\t{1}", i + 2, j);
if (s != "")
SetCell(oTable, i + 2, j, s, hgt,
j == 0 ? CellAlignment.MiddleLeft : CellAlignment.MiddleCenter);
}
}
//e.g. merge cells in the the very last row
//CellRange trg = new CellRange(nmRows - 1, 0, nmRows - 1, 3);
//oTable.MergeCells(trg);
//oTable.SetTextString(nmRows - 1, 0, "Merged cells are goes here");
oTable.SuppressRegenerateTable(false);
btr.AppendEntity(oTable);
tr.AddNewlyCreatedDBObject(oTable, true);
ed.Regen();
oTable.Dispose();
bt.Dispose();
btr.Dispose();
tr.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="poly"></param>
/// <param name="prec"></param>
/// <returns></returns>
public static List<string[]> PointsToTable(Polyline poly, int prec)
{
List<string[]> points = new List<string[]>();
for (int i = 0; i < poly.NumberOfVertices; i++)
{
SegmentType stype = poly.GetSegmentType(i);
if (stype == SegmentType.Line)
{
LineSegment3d seg = poly.GetLineSegmentAt(i);
if (i == 0)
{
Point3d p = seg.StartPoint;
string[] ptitem = new string[5];
ptitem[0] = (i + 1).ToString();
ptitem[1] = string.Format("{0:f" + prec + "}", p.X);
ptitem[2] = string.Format("{0:f" + prec + "}", p.Y);
ptitem[3] = string.Format("{0:f" + prec + "}", p.Z);
ptitem[4] = "";
points.Add(ptitem);
p = seg.EndPoint;
ptitem = new string[5];
ptitem[0] = (i + 2).ToString();
ptitem[1] = string.Format("{0:f" + prec + "}", p.X);
ptitem[2] = string.Format("{0:f" + prec + "}", p.Y);
ptitem[3] = string.Format("{0:f" + prec + "}", p.Z);
ptitem[4] = "";
points.Add(ptitem);
}
else
{
string[] ptitem = new string[5];
Point3d p = seg.EndPoint;
ptitem[0] = (i + 2).ToString();
ptitem[1] = string.Format("{0:f" + prec + "}", p.X);
ptitem[2] = string.Format("{0:f" + prec + "}", p.Y);
ptitem[3] = string.Format("{0:f" + prec + "}", p.Z);
ptitem[4] = "";
points.Add(ptitem);
}
}
else
{
if (stype == SegmentType.Arc)
{
CircularArc3d circ = poly.GetArcSegmentAt(i);
if (i == 0)
{
Point3d p = circ.StartPoint;
string[] ptitem = new string[5];
ptitem[0] = (i + 1).ToString();
ptitem[1] = string.Format("{0:f" + prec + "}", p.X);
ptitem[2] = string.Format("{0:f" + prec + "}", p.Y);
ptitem[3] = string.Format("{0:f" + prec + "}", p.Z);
ptitem[4] = "";
points.Add(ptitem);
double rad = circ.Radius;
Point3d cp = circ.Center;
ptitem = new string[5];
ptitem[0] = "Center";
ptitem[1] = string.Format("{0:f" + prec + "}", cp.X);
ptitem[2] = string.Format("{0:f" + prec + "}", cp.Y);
ptitem[3] = string.Format("{0:f" + prec + "}", cp.Z);
ptitem[4] = string.Format("{0:f" + prec + "}", rad);
points.Add(ptitem);
p = circ.EndPoint;
ptitem = new string[5];
ptitem[0] = (i + 2).ToString();
ptitem[1] = string.Format("{0:f" + prec + "}", p.X);
ptitem[2] = string.Format("{0:f" + prec + "}", p.Y);
ptitem[3] = string.Format("{0:f" + prec + "}", p.Z);
ptitem[4] = "";
points.Add(ptitem);
}
else
{
double rad = circ.Radius;
Point3d cp = circ.Center;
string[] ptitem = new string[5];
ptitem[0] = "Center";
ptitem[1] = string.Format("{0:f" + prec + "}", cp.X);
ptitem[2] = string.Format("{0:f" + prec + "}", cp.Y);
ptitem[3] = string.Format("{0:f" + prec + "}", cp.Z);
ptitem[4] = string.Format("{0:f" + prec + "}", rad);
points.Add(ptitem);
Point3d p = circ.EndPoint;
ptitem = new string[5];
ptitem[0] = (i + 2).ToString();
ptitem[1] = string.Format("{0:f" + prec + "}", p.X);
ptitem[2] = string.Format("{0:f" + prec + "}", p.Y);
ptitem[3] = string.Format("{0:f" + prec + "}", p.Z);
ptitem[4] = "";
points.Add(ptitem);
}
}
}
}
return points;
}
/// <summary>
///
/// </summary>
/// <param name="oTable"></param>
/// <param name="row"></param>
/// <param name="column"></param>
/// <param name="value"></param>
/// <param name="height"></param>
/// <param name="cellalign"></param>
public static void SetCell(Table oTable, int row, int column, string value,
double height, CellAlignment cellalign)
{
oTable.SetTextString(row, column, value);
oTable.SetTextHeight(row, column, height);
oTable.SetAlignment(row, column, cellalign);
}