- 积分
- 6614
- 明经币
- 个
- 注册时间
- 2006-8-30
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2014-9-18 17:44:33
|
显示全部楼层
+++++++++++++++++++++以下图形词典也无法通过(vlax-ldata-get)来取得数据
//--------------------------------------------------------------
// 功能:在命名对象词典中添加数据
// 作者:
// 日期:2007-7-20
// 说明:
//
//------------------------------------------------------------
[CommandMethod("AddInNOD")]
public void AddInNOD()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("在命名对象词典中添加数据\n");
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//获取命名对象词典(NOD)
DBDictionary NOD =trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite) as DBDictionary ;
// 声明一个新的词典
DBDictionary copyrightDict;
// 判断是否存在COPYRIGHT词典,没有则创建
try
{
// 获取COPYRIGHT词典
copyrightDict = (DBDictionary)trans.GetObject(NOD.GetAt("cheng5276-DIC"), OpenMode.ForRead);
}
catch
{
//在NOD下创建COPYRIGHT词典
copyrightDict = new DBDictionary();
NOD.SetAt("cheng5276-DIC", copyrightDict);
trans.AddNewlyCreatedDBObject(copyrightDict, true);
}
// 在copyrightDict中,获取或创建 "author" 词典
DBDictionary authorDict;
try
{
authorDict = (DBDictionary)trans.GetObject(copyrightDict.GetAt("Author"), OpenMode.ForWrite);
}
catch
{
authorDict = new DBDictionary();
//"author" doesn't exist, create one
copyrightDict.UpgradeOpen();
copyrightDict.SetAt("Author", authorDict);
trans.AddNewlyCreatedDBObject(authorDict, true);
}
// 通过Xrecord和ResultBuffer添加扩展数据
Xrecord authorRec;
try
{
authorRec = (Xrecord)trans.GetObject(authorDict.GetAt("AuthorInfo"), OpenMode.ForWrite);
}
catch
{
authorRec = new Xrecord();
authorRec.Data = new ResultBuffer(new TypedValue((int)DxfCode.Text, "张三"));
authorDict.SetAt("AuthorInfo", authorRec);
trans.AddNewlyCreatedDBObject(authorRec, true);
}
trans.Commit();
}
}
//--------------------------------------------------------------
// 功能:获取命名对象词典中的数据
// 作者:
// 日期:2007-7-20
// 说明:
//
//------------------------------------------------------------
[CommandMethod("Gid")]
//(vlax-ldata-GET "cheng5276-DIC" "AuthorInfo")
public void GetInNod()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("获取命名对象词典中数据\n");
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
// 获取NOD
DBDictionary NOD = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead, false);
// 获取COPYRIGHT词典
DBDictionary copyrightDict = (DBDictionary)trans.GetObject(NOD.GetAt("cheng5276-DIC"), OpenMode.ForRead);
// 获取Author词典
DBDictionary AuthorDict = (DBDictionary)trans.GetObject(copyrightDict.GetAt("Author"), OpenMode.ForRead);
// 获取AuthorInfo扩展记录Xrecord
Xrecord authorXRec = (Xrecord)trans.GetObject(AuthorDict.GetAt("AuthorInfo"), OpenMode.ForRead);
ResultBuffer resBuf = authorXRec.Data;
TypedValue val = resBuf.AsArray()[0];
ed.WriteMessage("该图纸由{0}设计\n", val.Value);
}
}
|
|