CAD恢复被删除的实体
程序员文章站
2024-03-18 18:37:28
...
/// <summary>
/// 删除实体、恢复被删除的实体
/// </summary>
/// <param name="dwg">当前文档</param>
/// <param name="entIds">删除/恢复的实体</param>
/// <param name="erasing">true:删除,false:恢复被删除的实体</param>
public static void EraseEntities(Document dwg, ObjectIdCollection entIds, bool erasing)
{
using (var tran = dwg.TransactionManager.StartTransaction())
{
foreach (ObjectId id in entIds)
{
Entity ent;
if (erasing)
{
if (!id.IsErased)
{
ent = (Entity)tran.GetObject(id, OpenMode.ForWrite);
ent.Erase();
}
}
else
{
if (id.IsErased)
{
ent = (Entity)tran.GetObject(id, OpenMode.ForWrite, true);
ent.Erase(false);
}
}
}
tran.Commit();
}
}