const double rowHeight = 3.0, colWidth = 5.0;
const double textHeight = rowHeight * 0.25;
[CommandMethod("MBT")]
static public void ModifyBlockTable()
{
DocumentCollection docs = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager;
Document aDoc = docs.MdiActiveDocument;
if (aDoc == null)
return;
Editor ed = aDoc.Editor;
// Let's start by asking for a table to be selected
// var per = ed.GetEntity("\nSelect table");
bool flag = false;
using (Database acCurDb = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database)
{
// Start our transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for read
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
ObjectId tbid = ObjectId.Null;
// Step through the Block table record
foreach (ObjectId asObjId in acBlkTblRec)
{
if (asObjId.ObjectClass.DxfName == "ACAD_TABLE")
{
tbid = asObjId;
Handle tbHandle = asObjId.Handle;
}
}
if (tbid != ObjectId.Null)
{
var tb = acTrans.GetObject(tbid, OpenMode.ForWrite) as Table;
// Insert our column, making it a bit skinnier than the others
tb.InsertColumns(0, colWidth * 0.5, 1);
// Populate the cells in this new column (starting with 1,
// as if we ask for 0 we'll get the header cell, too)
for (int i = 1; i < tb.Rows.Count; i++)
{
// Insert the index into the cell with appropriate text size
// and justification
var num = tb.Cells[i, 0];
num.Value = i;
num.Alignment = CellAlignment.MiddleCenter;
num.TextHeight = textHeight;
}
}
// Commit the transaction
acTrans.Commit();
}
acCurDb.SaveAs(@"D:\Test\Correct\318_FSA_PVU.dwg", DwgVersion.Current);
}
}