ODA Drawings SDK
|
The text style table object has the has() method for checking a text style in the table and the getAt() method for getting an existing text style from the table. In the examples below, the pTextStyles variable stores a pointer to the text style table object. The following example adds three text styles in the table and deletes one of them:
OdDbTextStyleTableRecordPtr pTextStyle;
pTextStyle = OdDbTextStyleTableRecord::createObject();
pTextStyle->setName("TextStyleX");
pTextStyles->add(pTextStyle);
pTextStyle = OdDbTextStyleTableRecord::createObject();
pTextStyle->setName("ErasedTextStyle");
pTextStyles->add(pTextStyle);
pTextStyle->erase(true);
pTextStyle = OdDbTextStyleTableRecord::createObject();
pTextStyle->setName("TextStyleY");
pTextStyles->add(pTextStyle);
To check whether a text style exists in the table, use the has() method of the text style table object that requires either the existing text style name or the ID associated with the existing text style record object as an argument of the method. The method returns True if the text style exists in the table or False if the text style is absent from the table or if it is erased. For example:
// Check the unerased text style object by name
odPrintConsoleString(L"\nTextStyleX %ls in the table", ((pTextStyles->has("TextStyleX")) ? L"exists" : L"absents"));
// Check the unerased text style object by ID
odPrintConsoleString(L"\nTextStyleY %ls in the table", ((pTextStyles->has(pTextStyle->objectId())) ? L"exists" : L"absents"));
// Check the erased text style object (result is absent)
odPrintConsoleString(L"\nErasedTextStyle %ls in the table", ((pTextStyles->has("ErasedTextStyle")) ? L"exists" : L"absents"));
To get a text style from the text style table, use the getAt() method of the text style table object that requires either the name or ID of the text style record object as a parameter for searching. The getAt() method has two implementations.
The first implementation of the getAt() method returns a smart pointer to an existing text style record object that satisfies the specified parameters and has three arguments:
To get the smart pointer to the text style record object, declare a variable of the OdDbTextstyleTableRecordPtr type and use the first implementation of the getAt() method. For example:
// Get the unerased text style object in the read mode
OdDbTextStyleTableRecordPtr pTextStyle1 = pTextStyles->getAt("TextStyleX");
// Get the unerased text style object in the write mode
OdDbTextStyleTableRecordPtr pTextStyle2 = pTextStyles->getAt("TextStyleY", OdDb::kForWrite, false);
// Get the unerased or erased text style object in the notify mode
OdDbTextStyleTableRecordPtr pTextStyle3 = pTextStyles->getAt("ErasedTextStyle", OdDb::kForNotify, true);
The second implementation of the getAt() method returns the OdDbObjectId instance associated with the text style record object that satisfies the specified name requirement and has two arguments:
To get the ID of the text style record object, declare a variable of the OdDbObjectId type and use the second implementation of the getAt() method. For example:
// Get the ID of the unerased text style object
OdDbObjectId idTextStyle1 = pTextStyles->getAt("TextStyleX");
// Get the ID of the unerased text style object
OdDbObjectId idTextStyle2 = pTextStyles->getAt("TextStyleY", false);
// Get the ID of the erased text style object
OdDbObjectId idTextStyle3 = pTextStyles->getAt("ErasedTextStyle", true);
To get the smart pointer to the text style using an ID, use the safeOpenObject() method of the OdDbObjectId object that opens the text style record object associated with the specified ID in the specified mode for the specified erase status, and returns the smart pointer to it. For example:
// Get the unerased text style object in the read mode using ID
OdDbTextStyleTableRecordPtr pTextStyle1 = idTextStyle1.safeOpenObject();
// Get the unerased text style object in the write mode using ID
OdDbTextStyleTableRecordPtr pTextStyle2 = idTextStyle2.safeOpenObject(OdDb::kForWrite, false);
// Get the unerased or erased text style object in the notify mode using ID
OdDbTextStyleTableRecordPtr pTextStyle3 = idTextStyle3.safeOpenObject(OdDb::kForNotify, true);
These operations can be combined in one line:
OdDbTextStyleTableRecordPtr pTextStyle = pTextStyles->getAt("TextStyleY").safeOpenObject(OdDb::kForWrite);
When the erase status is False, the getAt() method gets the text style record object if and only if it is marked as "unerased". When the erase status is True, the getAt() method gets the text style record object of any status, that is, marked as "erased" or "unerased".
The getAt() method returns the ID = kNull or smart pointer = Null when the text style with the specified name is absent from the text style table, is permanently deleted, cannot be opened in the specified mode, or is marked as "erased" and the status argument is False. For example:
// When ID = kNull
OdDbObjectId idTextStyle = pTextStyles->getAt("TextStyleN");
if(idTextStyle.isNull())
odPrintConsoleString(L"\nThe TextStyleN can not be opened\n");
// When Pointer = null
OdDbTextStyleTableRecordPtr pTextStyle = pTextStyles->getAt("TextStyleN", OdDb::kForWrite);
if(pTextStyle.isNull())
odPrintConsoleString(L"\nThe TextStyleN can not be opened\n");
Before getting a text style, use the has() method for checking whether the text style with the specified name exists in the text style table.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|