I'm programming an AutoCAD plugin in C#.NET. I need a way to set Table.IsReadEnabled
and Table.IsWriteEnabled
to true
. I have a method called addRow()
shown here:
public void addRow(String[] data)
{
OpenCloseTransaction tr = doc.TransactionManager.StartOpenCloseTransaction();
DocumentLock docLock = doc.LockDocument();
using (tr)
using (docLock)
{
bool isRead = IsReadEnabled;
bool isWrite = IsWriteEnabled;
BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.ModelSpace], OpenMode.ForWrite);
selectedRow++; //Sets the lowest empty row as the one to be modified
//Adding data to each cell
for (int i = 0; i < data.Length; i++)
{
Cells[selectedRow, i].SetValue(data[i], ParseOption.SetDefaultFormat);
}
GenerateLayout();
//Attempting to update database with new data
btr.AppendEntity(this);
tr.AddNewlyCreatedDBObject(this, true);
tr.Commit();
}
}
The first time it adds data to my table it works fine but the tr.Commit
call sets the table's IsReadEnabled
and IsWriteEnabled
to false even with an OpenClose
transaction. That causes AutoCAD to crash when it tries to add a new row of data to the table. I need to either re-enable writing and reading after the tr.commit
call or set it up so that writing and reading are never disabled.