Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Erasing and Recovering Objects

Erasing objects

A database object can be erased using the erase() method:


OdResult OdDbObject::erase(bool eraseIt = true);

The method takes the eraseIt argument that specifies whether the object is to be erased or unerased.

The erase() method with the true argument marks the record object as "erased", but it does not delete the object if the database is performing an undo procedure. If the database is not performing an undo, the method deletes the object permanently as soon as the database object is closed.

For example, to initialize the undo procedure and erase an object:


/**********************************************************************/
/* Enable undo procedure and start recording                          */
/**********************************************************************/
pDb->disableUndoRecording(false);
pDb->startUndoRecord();

/**********************************************************************/
/* Open the object for write and then mark it as erased               */
/**********************************************************************/
OdDbObjectPtr pObject = idRecord.safeOpenObject(OdDb::kForWrite);
pObject->erase(true);

Objects marked as erased cannot be opened by the default safeOpenObject() function; to open erased objects you need to pass the true value for the openErasedOne parameter:


pObject->objectId().safeOpenObject(OdDb::kForWrite,true);

Container objects such as block table records usually provide the skip/include option for erased elements when iterating over their contents. The default behavior is to skip erased elements.

Recovering objects

To recover an erased object call the erase() method with the false parameter value that marks the object as "unerased":


OdDbObjectPtr pObject = idObject.safeOpenObject(OdDb::kForWrite, true);
pObject->erase(false);

The recover procedure works only for objects which are not permanently erased. If the object was permanently deleted, the erase(false) method cannot recover it and generates the exception: "104 - Object was permanently deleted".

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.