Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Getting and Setting Strings

Tagged data can store a string value, grouped into the following categories:

  • Arbitrary strings — An arbitrary string can be up to 255 characters long and can contain any letters. Group codes 1 , 300 to 309, 410 to 419, 470 to 479, 1000, and 5005 define data as an arbitrary string.
  • Control strings — A control string can be "{" or "}" and subdivides tagged data into logical blocks. The left brace begins a block and the right brace ends a block. Group codes 102 and 1002 define data as a control string.
  • Names of objects — A name is a nonempty string that can be up to 255 characters long and can contain admissible letters for objects (see Naming objects). Group codes 2 to 4, 6 to 9, 1001, and 1003 define data as a name of an object.

In the following examples, the pRb variable stores a pointer to the resbuf-object, and the pDb variable stores a pointer to the database object.

Getting a String Value

To get any string value, use the getString() method which does not have arguments and returns an instance of the OdString type. For example:


OdString sValue = pRb->getString();
odPrintConsoleString(L"\nValue = %s", sValue.c_str());

To set the string value, use the setString() method which requires an instance of the OdString type as an argument and does not return a value.

Setting an Arbitrary String

To set an arbitrary string, pass the OdString instance and ascii- or wide-characters string to the setString() method. For example:


sValue = OD_T("Some Text");
pRb->setRestype(1000);
pRb->setString(sValue);

pRb->setRestype(300);
pRb->setString(L"wide-string");

pRb->setRestype(470);
pRb->setString("ascii-string");

Setting a Control String

To set a control string, pass the left brace for opening a block or right brace for closing a block to the setString() method. Only the 102 or 1002 codes are controlled and must be used in pairs: (102,"{") — (102,"}") for DXF technology or (1002,"{") — (1002,"}") for XData technology. For example:


// Open a block
pRb->setRestype(102);
pRb->setString("{");

// Close a block
pRb->setRestype(102);
pRb->setString("}");

Setting a Name of an Object

To set a name, set the data type corresponding to the specified object and pass the name of an existing object to the setString() method as a data value. For example:


// Set the layer name
OdDbLayerTableRecordPtr pLayer = pDb->getLayerZeroId().safeOpenObject();

pRb->setRestype(1003);
pRb->setString(pLayer->getName());

// Set the text style name
OdDbTextStyleTableRecordPtr pTextStyle = pDb->getTextStyleStandardId().safeOpenObject();

pRb->setRestype(7);
pRb->setString(pTextStyle->getName());

Note: The passed data value must correspond to the specified data type, otherwise the exception "68 - Invalid ResBuf" occurs. When a string is a name, the object must exist in the database.

See Also

Working with Tagged Data

Determining the Data Type by Group Code

Example of Entering and Displaying Tagged Data

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