我正在C#.NET中编写AutoCAD插件。我需要一种将Table.IsReadEnabledTable.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();

            }
        }


第一次将数据添加到我的表中时,它可以正常工作,但是tr.Commit调用将表的IsReadEnabledIsWriteEnabled设置为false,即使使用OpenClose事务也是如此。这会导致AutoCAD在尝试向表中添加新的数据行时崩溃。我需要在tr.commit调用后重新启用写入和读取功能,或者将其设置为永远不会禁用写入和读取功能。

最佳答案

if (!IsWriteEnabled || !IsReadEnabled) //Committing transactions closes everything for reading and writing so it must be reopened
{
    tr.GetObject(this.ObjectId, OpenMode.ForRead);
    tr.GetObject(this.ObjectId, OpenMode.ForWrite);
}


我只需要添加一个if语句!

关于c# - AutoCAD eNotOpenForWrite,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26367657/

10-11 02:18