Hi,
When you create a new Database for reading a dwg file (db.ReadDwgFile) you have to use false for the buildDefaultDrawing argument. And you do not need to do it twice.
Try like this (not tested):
using (DocumentLock acLckDoc = acdoc.LockDocument())
{
using (var newDb = new Database(false, true))
{
//Create a new .dwg using a template drawing.
newDb.ReadDwgFile(dwgtemplate, FileOpenMode.OpenForReadAndAllShare, false, null);
// Start a transaction in the new database
using (Transaction acTrans = newDb.TransactionManager.StartTransaction())
{
// Import the Excel BOM as a datatable.
System.Data.DataTable bomDT = Excel.LoadCSVFile(dwgBOMCSV);
int totalRows = bomDT.Rows.Count;
totalRows += 2;
string[,] bomArray = new string[totalRows, 4];
bomArray[1, 0] = "TAG";
bomArray[1, 1] = "DESCRIPTION";
bomArray[1, 2] = "CATALOG";
bomArray[1, 3] = "QTY";
int i = 2;
// Load the datatable into an array
foreach (DataRow item in bomDT.Rows)
{
var tag = item[0].ToString();
var description = item[1].ToString();
var catalog = item[2].ToString();
var qty = item[3].ToString();
ed.WriteMessage("\n" + item[2]);
bomArray[i, 0] = tag;
bomArray[i, 1] = description;
bomArray[i, 2] = catalog;
bomArray[i, 3] = qty;
i += 1;
}
var bt = acTrans.GetObject(newDb.BlockTableId, OpenMode.ForRead) as BlockTable;
var tb = new Table();
tb.TableStyle = newDb.Tablestyle;
// insert rows and columns
totalRows -= 1;
tb.InsertRows(1, .2533, totalRows);
tb.InsertColumns(0, 2, 1);
tb.InsertColumns(0, 7, 1);
tb.InsertColumns(0, 2, 1);
tb.Position = new Point3d(1.5, 22, 0);
totalRows += 1;
for (int a = 1; a < totalRows; a++)
{
for (int b = 0; b < 4; b++)
{
string itemToInsert = bomArray[a, b];
tb.Cells[a, b].TextHeight = .1033;
tb.Cells[a, b].TextString = itemToInsert;
tb.Cells[a, b].Alignment = CellAlignment.MiddleCenter;
}
}
tb.GenerateLayout();
var btr = acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(tb);
acTrans.AddNewlyCreatedDBObject(tb, true);
acTrans.Commit();
}
newDb.SaveAs(bomDwg, DwgVersion.Current);
}
}
HostApplicationServices.WorkingDatabase = acDb;
}