- [CommantMethod("ADDINI")]
- public static void AddIni()
- {
- try
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- DBDictionary NOD =(DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
- DBDictionary dict;//作为主字典中INI键的值
- if (NOD.Contains("INI"))
- {
- dict = (DBDictionary)tr.GetObject(NOD.GetAt("BLSZ"), OpenMode.ForWrite);
- }
- else
- {
- dict = new DBDictionary();
- NOD.UpgradeOpen();
- NOD.SetAt("INI", dict);
- tr.AddNewlyCreatedDBObject(dict, true);
- }
- ResultBuffer resBuf = new ResultBuffer();
- resBuf.Add(new TypedValue((int)DxfCode.Text, "A"));
- resBuf.Add(new TypedValue((int)DxfCode.Text, "B"));
- Xrecord xRec = new Xrecord();
- xRec.Data = resBuf;
- dict.SetAt("INIS", xRec);
- tr.AddNewlyCreatedDBObject(xRec, true);
- tr.Commit();
- }
- }
- catch {
- }
- }
- [CommandMethod("GETINI")]
- public static void GetINI()
- {
- try
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Edotor ed=doc.Editor;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- DBDictionary NOD = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
- if (NOD.Contains("INI"))
- {
- DBDictionary dict = tr.GetObject(NOD.GetAt("INI"), OpenMode.ForRead) as DBDictionary;
- Xrecord xRec = tr.GetObject(dict.GetAt("INIS"), OpenMode.ForRead) as Xrecord;//获取值
- foreach (var xdata in xRec.Data)
- {
- ed.WriteMessage(xdata.Value.ToString()+"\n");
- }
- }
- }
- }
- catch{
- }
- }
- ————————————————
- 版权声明:本文为CSDN博主「淡定vs冷漠」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
- 原文链接:https://blog.csdn.net/qq_21489689/article/details/79061759
|