AutoCAD二次开发(.Net)之DBDictionary信息的添加与获取

        [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{
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值