gpt4 book ai didi

c# - AutoCAD eNotOpenForWrite

转载 作者:行者123 更新时间:2023-11-30 17:46:19 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com