用.Net开发Cad

Cad二次开发

 

删除扩展数

打印 上一主题 下一主题
 
       
 
        public static void RemoveXData(Entity EntObject, string XDataName)
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                try
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        DBObject obj = tr.GetObject(EntObject.ObjectId, OpenMode.ForWrite);
                        ResultBuffer rb = obj.XData;
                        if (rb != null)
                        {
                            TypedValue[] values = rb.AsArray();
                            for (int i = 0; i < values.Length; i++)
                            {
                                if (values<i>.TypeCode == (int)DxfCode.ExtendedDataRegAppName && values<i>.Value.ToString() == XDataName)
                                {
                                    //移除之 
                                    TypedValue[] values_New = { new TypedValue((int)DxfCode.ExtendedDataRegAppName, values<i>.Value.ToString()) };
                                    ResultBuffer rb_New = new ResultBuffer(values_New);
                                    obj.UpgradeOpen();
                                    obj.XData = rb_New;
                                    obj.DowngradeOpen();
                                }
                            }
                        }
                        tr.Commit();
                    }
                }
                catch (System.Exception exc)
                {
                    ed.WriteMessage(exc.Message);
                }
            }
        }
 

posted on 2011-09-19 19:19  xuguangren  阅读(236)  评论(0编辑  收藏  举报

导航