本帖最后由 qq1254582201 于 2024-9-6 09:55 编辑
- [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{
- }
- }
- 原文链接:https://blog.csdn.net/qq_21489689/article/details/79061759
原文链接:https://blog.csdn.net/qq_21489689/article/details/79061759 |