- 积分
- 8245
- 明经币
- 个
- 注册时间
- 2005-2-21
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
最近有朋友找删除实体的扩展数据,看来还是在此发个贴,以便大家学习参考:
-
- 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.TypeCode == (int)DxfCode.ExtendedDataRegAppName && values.Value.ToString() == XDataName)
- {
- //移除之
- TypedValue[] values_New = { new TypedValue((int)DxfCode.ExtendedDataRegAppName, values.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);
- }
- }
- }
|
|