Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Deleting and Recovering a Text Style

The text style table object does not have a method for deleting a text style. Each text style record object deletes itself. When the text style deletes itself, the database marks it as "erased", and the text style is continued tobe stored in the text style table until the database is not saved in a file. This gives the ability to recover text styles. Recovery is possible only if the undo procedure is begun for the database, otherwise objects are deleted permanently. In the example below, the pTextStyles variable stores a pointer to the text style table object. For example, add a text style in the table:


OdDbTextStyleTableRecordPtr pTextStyle = OdDbTextStyleTableRecord::createObject();
pTextStyle->setName("TextStyleX");
pTextStyles->add(pTextStyle);

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


pTextStyles->database()->startUndoRecord();

Deleting a Text Style

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


pTextStyle = pTextStyles->getAt("TextStyleX", OdDb::kForWrite);
OdResult result = pTextStyle->erase(true);

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


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

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

If the text style is the current active text style or is a predefined text style (Standard), the erase() method generates the exception: «116 - Object can't be erased». Therefore, check the text style before deleting. For example:


if(pTextStyle->objectId() == pTextStyles->database()->getTextStyleStandardId())
  odPrintConsoleString(L"\nError: Standard text style can not be deleted"); 

if(pTextStyle->objectId() == pTextStyles->database()->getTEXTSTYLE())
  odPrintConsoleString(L"\nError: Current active text style can not be deleted"); 

Recovering a Text Style

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


pTextStyle = pTextStyles->getAt("TextStyleX", OdDb::kForWrite, true);
if(!pTextStyle.isNull())
  pTextStyle->erase(false);

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

Note: The text style table must not be empty because new text entities will obtain OdDb::kNull instead of the text style ID—this action creates the invalid situation.

See Also

Working with Text Styles

Making a Text Style Active

Adding and Naming Text Styles

Getting and Checking Text Styles

Example of Working with the Text Style Table Object

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