删除实体的扩展数据
最近有朋友找删除实体的扩展数据,看来还是在此发个贴,以便大家学习参考: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);
}
}
}
正好需要,收藏了。 本帖最后由 chpmould 于 2011-9-19 22:01 编辑
先占个位,有空再研究下. 先占个位,有空再研究下. 占楼强烈支持响铃大大,嘿嘿
最近.net版块很冷清哦,多放些程序呀 谢了,收藏了
页:
[1]