- 积分
- 1731
- 明经币
- 个
- 注册时间
- 2003-4-26
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
我编子一个修改命名词典记录的函数,但文件中如有同名记录则无法保存,运行到db.TransactionManager.AddNewlyCreatedDBObject(authorRec, true)时就出错。
有大侠帮忙看看
代码:
public ResultBuffer setDictList(string Dic1, string Xre1, ResultBuffer Real1) {
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
///Database db = HostApplicationServices.WorkingDatabase;
///Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
///ed.WriteMessage(Real1.ToString());
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//获取命名对象词典类(NOD)
DBDictionary NOD;
try
{
NOD = trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite) as DBDictionary;
}
catch
{
return null;
}
// 声明一个新的词典对象
DBDictionary copyrightDict;
// 判断是否存在COPYRIGHT词典,没有则创建
try
{
// 获取COPYRIGHT词典
copyrightDict = (DBDictionary)trans.GetObject(NOD.GetAt(Dic1), OpenMode.ForRead);
}
catch
{
//在NOD下创建COPYRIGHT词典
copyrightDict = new DBDictionary();
NOD.SetAt(Dic1, copyrightDict);///产生新的有名词典
try
{
///保存新的有名词典
db.TransactionManager.AddNewlyCreatedDBObject(copyrightDict, true);
}
catch
{
return null;
}
}
// 通过Xrecord和ResultBuffer添加扩展数据
Xrecord authorRec;
///产生一个记录的对象
try
{
///词典有无此记录的对象
authorRec = (Xrecord)trans.GetObject(copyrightDict.GetAt(Xre1), OpenMode.ForWrite);
}
catch
{
authorRec = new Xrecord();
}
ed.WriteMessage("\n111");
///authorRec.Data = new ResultBuffer(new TypedValue((int)DxfCode.Real, Real1));
///ed.WriteMessage(Real1.ToString());
authorRec.Data = Real1; ///把数据加入记录中
ed.WriteMessage("\n222");
copyrightDict.UpgradeOpen(); //扩展字典切换成写的状态。
ed.WriteMessage("\n333");
copyrightDict.SetAt(Xre1, authorRec);
ed.WriteMessage("\n444\n");
///trans.AddNewlyCreatedDBObject(authorRec, true); //必须加,否则修改后无法保存。
db.TransactionManager.AddNewlyCreatedDBObject(authorRec, true); //必须加,否则修改后无法保存。
ed.WriteMessage("\n5555");
copyrightDict.DowngradeOpen(); //为安全,扩展字典切换成读的状态。
ed.WriteMessage("\n666");
trans.Commit();
return Real1;
}
}
|
|