Author Topic: Erased Objects  (Read 2285 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Erased Objects
« on: July 27, 2016, 07:43:11 PM »
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:
Code - C#: [Select]
  1. /// <summary>
  2. /// Erase the object  from the current document
  3. /// </summary>
  4. /// <param name="id">ObjectID of the object to be erased</param>
  5. public static void Erase(ObjectId id)
  6. {
  7.         if (id == ObjectId.Null) return;
  8.         using (LockedTransaction acTr = Active.Document.TransactionManager.StartLockedTransaction())
  9.         {
  10.                 DBObject obj = acTr.GetObject(id, OpenMode.ForWrite, true);//<- if openErased is set to false and ent was erased, this chucks a wobbly about eWasErased
  11.                 obj?.Erase(true);
  12.                 acTr.Commit();
  13.         }
  14. }

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?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2121
  • class keyThumper<T>:ILazy<T>
Re: Erased Objects
« Reply #1 on: July 27, 2016, 08:01:49 PM »
Does this Help ?

public bool IsErased { get; }
Declaring Type: Autodesk.AutoCAD.DatabaseServices.ObjectId
Assembly: Acdbmgd, Version=21.0.0.0

AutoCAD uses this property to facilitate it's UNDO process.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Erased Objects
« Reply #2 on: July 27, 2016, 08:17:16 PM »
From docs info if helps explains anything.

Quote
Code: [Select]
Acad::ErrorStatus erase(
    Adesk::Boolean erasing = true
);
Parameters

Code: [Select]
Adesk::Boolean erasing = true  Input Boolean indicating if object is to be erased or unerased 

Description
Sets the erase bit of the object. If erasing == Adesk::kTrue, then the erase bit is set on. If erasing == Adesk::kFalse, then the erase bit is set off.

 

Note
This does not remove the object from the database, nor from memory. However, if the erase bit is set when the database is saved or output to DXF, the object is not filed out and thus is not present the next time the file is opened.



Quote
Any object in the database can be erased with the following function:

Code: [Select]
Acad::ErrorStatus
AcDbObject::erase(
    Adesk::Boolean Erasing = true);
Note The erase() function has different results for database objects and entities, with consequences for unerasing them:
  • When a database object is erased, information about that object is removed from the dictionary. If the object is unerased with erase(kfalse), the information is not automatically reintroduced. You must use the setAt() function to add the information to the dictionary again.
  • When an entity is erased, it is simply flagged as erased in the block table record. The entity can be unerased with erase(kfalse).
By default, you cannot open an erased object with the acdbOpenObject() function. If you attempt to do so, the eWasErased error code will be returned.

Code: [Select]
extern Acad::ErrorStatus
acdbOpenObject(
    AcDbObject*& obj,
    AcDbObjectId objId,
    AcDb::OpenMode openMode,
    Adesk::Boolean openErasedObject = Adesk::kFalse);
To open an erased object, use kTrue for the last parameter of the acdbOpenObject() function.

Container objects such as polylines and block table records usually provide the option of skipping erased elements when iterating over their contents. The default behavior is to skip erased elements.

Erased objects are not filed out to DWG or DXF files.