C# AutoCAD eNotOpenForWrite
我正在用C#.NET编写一个AutoCAD插件。我需要一种方法将C# AutoCAD eNotOpenForWrite,c#,.net,autocad,C#,.net,Autocad,我正在用C#.NET编写一个AutoCAD插件。我需要一种方法将Table.IsReadEnabled和Table.IsWriteEnabled设置为true。我有一个名为addRow()的方法,如下所示: public void addRow(String[] data) { OpenCloseTransaction tr = doc.TransactionManager.StartOpenCloseTransaction();
Table.IsReadEnabled
和Table.IsWriteEnabled
设置为true
。我有一个名为addRow()
的方法,如下所示:
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();
}
}
public void addRow(字符串[]数据)
{
OpenCloseTransaction tr=doc.TransactionManager.StartOpenCloseTransaction();
DocumentLock docLock=doc.LockDocument();
使用(tr)
使用(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++;//将最低的空行设置为要修改的空行
//向每个单元格添加数据
for(int i=0;i
第一次向我的表中添加数据时,它工作正常,但是
tr.Commit
调用将表的IsReadEnabled
和IsWriteEnabled
设置为false,即使使用OpenClose
事务。这会导致AutoCAD在尝试向表中添加新行数据时崩溃。我需要在tr.commit
调用后重新启用写入和读取,或者将其设置为永不禁用写入和读取。我认为您应该使用StartTransaction
而不是startopconseletransaction
。见附件博客
干杯,
阿兰
我只需要添加一个if语句 当上一个事务未正确处理时,很可能会发生此错误。 问题中的“addRow”函数是如何不编码的示例。 始终使用C#“using”语句启动事务。它确保事务被正确地处理。检查并修复代码中启动事务的所有位置
using(OpenCloseTransaction tr = doc.TransactionManager.StartOpenCloseTransaction())
{
// your logic here
}
使用try-catch获取确切的异常。此外,交易也丢失。我很想这样做,但在接下来的3个小时内我不能这样做
using(OpenCloseTransaction tr = doc.TransactionManager.StartOpenCloseTransaction())
{
// your logic here
}