Drawings SDK Developer Guide > Working with .dwg Files > Working with Databases > Working with Database Containers > Working with Predefined Tables of Named Records > Working with Specific Predefined Tables of Named Records > UCSs Table > Manipulating of UCSs > Deleting and Recovering UCSs
Deleting and Recovering UCSs

The UCS table object does not have a method for deleting a UCS. Instead, each UCS record object deletes itself. When the UCS deletes itself, the database marks it as "erased" and the UCS continues to be stored in the UCS table until the database is not saved in a file. This gives the ability to recover UCSs. Recovery is possible only if the undo process is begun for the database, otherwise objects are deleted permanently. The pUCSs variable stores a pointer to the UCS table object. For example, add a UCS in the table:


OdDbUCSTableRecordPtr pUCS = OdDbUCSTableRecord::createObject();
pUCS->setName("UCS1");
pUCSs->add(pUCS);

To start the undo process, use the startUndoRecord() method of the database object. For example:


pUCSs->database()->startUndoRecord();

Deleting a UCS

To delete a UCS, get the smart pointer to the UCS record object in write mode and use the erase() method when its argument equals True. The erase() method marks the UCS as «erased» and returnsthe result status in the OdResult value. For example:


pUCS = pUCSs->getAt("UCS1", OdDb::kForWrite);
OdResult result = pUCS->erase(true);

The program can use the obtained result value for verification. For example:


if(result) 
  odPrintConsoleString(L"\nError: %d - %ls", result, pUCSs->database()->appServices()->getErrorDescription(result)); 

If the UCS record object is not opened in write mode, the erase() method generates the exception: «62 - Not opened for write».

Recovering a UCS

A UCS marked as «erased» is stored in the database and can be recovered from the UCS table; the program must start the undo process for the database, otherwise the erase()method deletes the UCS permanently. To recover a UCS, get the smart pointer to the deleted UCS record object in the write mode and use the erase() method when its argument equals False. The erase() method marks the UCS as «unerased». For example:


pUCS = pUCSs->getAt("UCS1", OdDb::kForWrite, true);
if(!pUCS.isNull())
  pUCS->erase(false);

If the UCS was permanently deleted, the erase(false) method cannot recover it and generates the exception: «104 - Object was permanently deleted».

See Also

Working with UCSs

Adding and Naming UCSs

Getting and Checking UCSs

Example of Working with the UCS Table Object

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