- 积分
- 6653
- 明经币
- 个
- 注册时间
- 2006-8-30
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
小弟今日通过如下方法给图纸添加词典后,图纸竟然无法保存,实在不解,求老大们指点
,
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();
}
}
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|