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 > Text Styles Table > Organization of Text Styles
Organization of Text Styles

The database stores all text styles in a text style table. The text style is a record of the text style table. The text style table is a predefined object which exists in the database initially and cannot be deleted from the database. The database contains a set of predefined text styles that also exists initially in the text style table and cannot be deleted.

The OdDbTextStyleTable class is the text style table object that represents the interface for accessing the text style table and manipulating the text styles in it. The OdDbTextStyleTableRecord class is the text style record object that represents the interface for accessing a text style and manipulating its properties. The text style table object has the AcDbTextStyleTable class name, and the text style record object has the AcDbTextStyleTableRecord class name.

The OdDbTextStyleTablePtr class is the typified smart pointer to an instance of the text style table and is used to store and pass references to the text style table object. The OdDbTextStyleTableRecordPtr class is the typified smart pointer to an instance of the text style and is used for storing and passing references to the text style record object. The pDb variable stores the pointer to the database object.

To get the text style table, use the getTextStyleTableId() method of the database object; it does not have arguments and returns the OdDbObjectId instance associated with the text style table object. For example:


OdDbObjectId idTextStyles = pDb->getTextStyleTableId();

To manipulate text styles, the program must open the text style table object and get a smart pointer to it. If the text style table object is opened in read mode, the program can obtain the text styles and their properties, but it cannot modify them, cannot add a new text style, and cannot delete an existing text style from the table. If the text style table object is opened in write mode, the program can add a new text style in the table, rename any text style, modify the properties of an existing text style, or delete a text style from the table.

To get the smart pointer to the text style table object, declare a variable of the OdDbTextStyleTablePtr type and use the safeOpenObject() method of the obtained OdDbObjectId object. The text style table is a predefined object and the erase status is not applicable. Therefore the safeOpenObject() method requires only the open mode as a value of the OdDb::OpenMode enumerator (kForRead, kForWrite, or kForNotify) and returns the smart pointer to the text style table object. For example:


// Open the text style table object in the read mode
OdDbTextStyleTablePtr pTextStyles = idTextStyles.safeOpenObject(OdDb::kForRead);

// Open the text style table object in the write mode
OdDbTextStyleTablePtr pTextStyles = idTextStyles.safeOpenObject(OdDb::kForWrite);

These operations can be combined to one line:


OdDbTextStyleTablePtr pTextStyles = pDb->getTextStyleTableId().safeOpenObject(OdDb::kForWrite);

The text style table object contains a predefined text style, named "Standard", that is used as the default object associated with other objects of the database. To get the predefined text style, use the getTextStyleStandardId() method of the database which returns the OdDbObjectId instance associated with the "Standard" text style. For example:


OdDbTextStyleTableRecordPtr pStandardTextStyle = pDb->getTextStyleStandardId().safeOpenObject();
odPrintConsoleString(L"\nThe predefined text style is \"%ls\"", pStandardTextStyle->getName().c_str());

The text style table object has the following specific methods: add() method for adding a new text style in the table, getAt() method for getting an existing text style from the table, has() method for checking whether the text style exists in the table, and newIterator() method for iterating through text styles of the table.

See Also

Working with Text Styles

Manipulating of Text Styles

Working with Predefined Tables of Named Records

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