求助 添加图形词典数据后,无法保存文件
小弟今日通过如下方法给图纸添加词典后,图纸竟然无法保存,实在不解,求老大们指点,
public static void AddDictionary(string Dicname, string XrecordName, object val)
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
DBDictionary NOD = trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite) as DBDictionary;
DBDictionary Dict;
try
{
Dict = (DBDictionary)trans.GetObject(NOD.GetAt(Dicname), OpenMode.ForWrite);
}
catch
{
Dict = new DBDictionary();
NOD.SetAt(Dicname, Dict);
trans.AddNewlyCreatedDBObject(Dict, true);
}
// 通过Xrecord和ResultBuffer添加扩展数据
Xrecord xRec=new Xrecord();
System.Type tp = val.GetType();
try
{
xRec = (Xrecord)trans.GetObject(Dict.GetAt(XrecordName), OpenMode.ForWrite);
}
catch
{
}
finally
{
if (tp == typeof(int))
{
xRec.Data = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataInteger32, val));
}
else if (tp == typeof(string))
{
xRec.Data = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataAsciiString, val));
}
else
{
xRec.Data = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataReal, val));
}
Dict.SetAt(XrecordName, xRec);
// trans.AddNewlyCreatedDBObject(xRec, true);
trans.Commit();
}
}
}
看这里最后部分
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=76123 谢谢老大,原来必须要加这句 NOD.UpgradeOpen();
不是这句 是后面那句
页:
[1]