- 积分
- 11621
- 明经币
- 个
- 注册时间
- 2004-10-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2011-9-16 12:39:19
|
显示全部楼层
问题已解决
首先建立词典条目Xggj_Tool
并设置Xggj_Tool的值为1000,
- //将比例尺设置到词典对象,词典条目名称为Xggj_Tool
- Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database acCurDb = acDoc.Database;
- Transaction trans = acCurDb.TransactionManager.StartTransaction();
- DocumentLock dl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- try
- {
- //首先,获取NOD……
- DBDictionary NOD = (DBDictionary)trans.GetObject(acCurDb.NamedObjectsDictionaryId, OpenMode.ForWrite);
- //定义一个自定义级别的字典"Xggj_Tool"
- DBDictionary acmeDict;
- try
- {
- //如果Xg_Tool不存在,则转到catch块,这里什么也不做
- acmeDict = (DBDictionary)trans.GetObject(NOD.GetAt("Xggj_Tool"), OpenMode.ForRead);
- }
- catch
- {
- //如果Xggj_Tool不存在,则创建它并把它加入到NOD中……
- acmeDict = new DBDictionary();
- NOD.SetAt("Xggj_Tool", acmeDict);
- trans.AddNewlyCreatedDBObject(acmeDict, true);
- Xrecord mgrXRec;
- try
- {
- mgrXRec = (Xrecord)trans.GetObject(acmeDict.GetAt("Xggj_Scales"), OpenMode.ForWrite);
- }
- catch
- {
- mgrXRec = new Xrecord();
- mgrXRec.Data = new ResultBuffer(new TypedValue((int)DxfCode.Text, "1000"));
- acmeDict.SetAt("Xggj_Scales", mgrXRec);
- trans.AddNewlyCreatedDBObject(mgrXRec, true);
- }
- }
- trans.Commit();
- }
- finally
- {
- dl.Dispose();
- }
复制代码 读取Xggj_Tool的值
- //读取词典对象的值
- Transaction trans1 = acCurDb.TransactionManager.StartTransaction();
- DBDictionary NOD1 = (DBDictionary)trans1.GetObject(acCurDb.NamedObjectsDictionaryId, OpenMode.ForRead);
- DBDictionary Dict1 = (DBDictionary)trans1.GetObject(NOD1.GetAt("Xggj_Tool"), OpenMode.ForRead);
- Xrecord salesXRec = (Xrecord)trans1.GetObject(Dict1.GetAt("Xggj_Scales"), OpenMode.ForRead);
- TypedValue resBuf = salesXRec.Data.AsArray()[0];
- acDoc.Editor.WriteMessage("当前词典对象的值为:" + Convert.ToString(resBuf.Value));
- trans1.Commit();
复制代码 运行命令行显示:“当前词典对象的值为:1000“
|
|