[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{
}
}
AutoCAD二次开发(.Net)之DBDictionary信息的添加与获取
最新推荐文章于 2024-01-11 21:47:26 发布