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 > Linetypes Table > Manipulating of Linetypes > Deleting and Recovering Linetypes
Deleting and Recovering Linetypes

The linetype table object does not have a method for deleting a linetype. Each linetype record object deletes itself. When the linetype deletes itself, the database marks it as "erased", and the linetype continues to be stored in the linetype table until the database is not saved in a file. This provides the ability to recover linetypes. Recovery is possible only if the undo process is started for the database, otherwise any objectsare deleted permanently.

In the following examples, the pLinetypes variable stores a pointer to the linetype table object. For example, add a linetype in the table:


OdDbLinetypeTableRecordPtr pLinetype = OdDbLinetypeTableRecord::createObject();
pLinetype->setName("LinetypeX");
pLinetypes->add(pLinetype);

To start the undo process, use the startUndoRecord() method of the database object. To get the database object from the linetype table object, use the database() method of it. For example:


pLinetypes->database()->startUndoRecord();

Deleting a linetype

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


pLinetype = pLinetypes->getAt("LinetypeX", OdDb::kForWrite);
OdResult result = pLinetype->erase(true);

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


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

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

If the linetype is the current active linetype or is predefined (ByLayer, ByBlock, Continuous), the erase() method generates the exception: «116 - Object can't be erased». Therefore, check the linetype before deletion. For example:


if(pLinetype->objectId() == pLinetypes->database()->getLinetypeByLayerId())
  odPrintConsoleString(L"\nError: ByLayer linetype can not be deleted"); 

if(pLinetype->objectId() == pLinetypes->database()->getLinetypeByBlockId())
  odPrintConsoleString(L"\nError: ByBlock linetype can not be deleted"); 

if(pLinetype->objectId() == pLinetypes->database()->getLinetypeContinuousId())
  odPrintConsoleString(L"\nError: Continuous linetype can not be deleted"); 

if(pLinetype->objectId() == pLinetypes->database()->getCELTYPE())
  odPrintConsoleString(L"\nError: Current active linetype can not be deleted"); 

Recovering a linetype

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


pLinetype = pLinetypes->getAt("LinetypeX", OdDb::kForWrite, true);
if(!pLinetype.isNull())
  pLinetype->erase(false);

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

Note: The linetype table must not be empty because new entities will obtain OdDb::kNull instead of a linetype ID by default, and this action creates a invalid situation.

See Also

Working with Linetypes

Make a Linetype Active

Adding and Naming Linetypes

Getting and Checking Linetypes

Example of Working with the Linetype Table Object

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