I'm having some trouble understanding erased objects.
My code has managed to throw more than it's share of eWasErased errors, and I'm trying to understand why.
The following method is pretty simple:
/// <summary>
/// Erase the object from the current document
/// </summary>
/// <param name="id">ObjectID of the object to be erased</param>
public static void Erase(ObjectId id)
{
if (id == ObjectId.Null) return;
using (LockedTransaction acTr = Active.Document.TransactionManager.StartLockedTransaction())
{
DBObject obj = acTr.GetObject(id, OpenMode.ForWrite, true);//<- if openErased is set to false and ent was erased, this chucks a wobbly about eWasErased
obj?.Erase(true);
acTr.Commit();
}
}
I store handles of objects in xData, later I read a handle, convert to ObjectID and do something with the entity. I need to account for the possibility that the user has deleted the entity in question.
Is there a best practice for working with Entities that may have been erased?