删除扩展数据

 1         public static void RemoveXData(Entity EntObject, string XDataName)
2 {
3 Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
4 Database db = HostApplicationServices.WorkingDatabase;
5
6 using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
7 {
8 try
9 {
10 using (Transaction tr = db.TransactionManager.StartTransaction())
11 {
12 DBObject obj = tr.GetObject(EntObject.ObjectId, OpenMode.ForWrite);
13 ResultBuffer rb = obj.XData;
14 if (rb != null)
15 {
16 TypedValue[] values = rb.AsArray();
17 for (int i = 0; i < values.Length; i++)
18 {
19 if (values[i].TypeCode == (int)DxfCode.ExtendedDataRegAppName && values[i].Value.ToString() == XDataName)
20 {
21 //移除之
22 TypedValue[] values_New = { new TypedValue((int)DxfCode.ExtendedDataRegAppName, values[i].Value.ToString()) };
23 ResultBuffer rb_New = new ResultBuffer(values_New);
24 obj.UpgradeOpen();
25 obj.XData = rb_New;
26 obj.DowngradeOpen();
27 }
28 }
29 }
30 tr.Commit();
31 }
32 }
33 catch (System.Exception exc)
34 {
35 ed.WriteMessage(exc.Message);
36 }
37 }
38 }
posted @ 2011-11-09 11:04  hunklee  阅读(306)  评论(0编辑  收藏  举报