Close

Relief for ODA Team in Ukraine

Learn more
ODA BimRv SDK
Work with Text Elements

Text elements are instances of the OdBmTextNote class. To work with them, you need to create them and add them to a database.
Text elements are used to display text in a drawing. For example, to explain what's going on in a very tight area, you can use text notes.
Text notes are created and registered in the database with the usual element interfaces, which means, you only need to define text-specific data.
In the picture below you can see what can be achieved with text elements:

The main properties of text elements are:

  • View that the text is added to
  • Text
  • Position
  • Direction
  • Width

Except the Text property, all other values are optional and are initialized with default values.

Property Default value
View ID ID of the active view
Origin (0, 0, 0)
Text alignment Left/top
Direction View right direction
Width Width of the text without wrapping
Left leader attachment Top line
Right leader attachment Bottom line

There are a number of methods to set the properties mentioned above.
Member Method Description
View setOwnerDBViewId(OdBmObjectId) Interface is inherited from the element and defines the view the text element is created in. The view ID must not be changed after adding the element to the database.
Text setRawText(OdString&) Sets text from a raw text string.
Text setRtfText(OdAnsiString&) Sets text from an RTF text string.
Position setOrigin(OdGePoint3d) Sets the origin of the text. Depending on the text alignment origin, it is the point at the left/center/right top/center/bottom of the text. For example, for left-horizontal alignment and top-vertical alignment, the origin is the top left point.
Position setVertAlign(OdBm::VerticalAlignment::Enum) Sets the vertical alignment.
Position setHorzAlign(OdBm::HorizontalAlignment::Enum) Sets the horizontal alignment.
Direction setDirection(OdGeVector3d) Sets the horizontal direction of the text. The vertical direction of the text is calculated automatically with the setting of the horizontal direction using the view direction as a normal.
Width setWidth(double) Sets the width of the text. If this width is smaller than the width of the text on one line, the text is wrapped.
Direction setKeepReadable(bool) Sets the keep readable mode. If on, text is always drawn from left to right (or from bottom to top if it is parallel to the y-axis). If text that has this flag turned on has a direction oriented from right to left or top to bottom, the text is rotated by 180 degrees when rendered.
Width setLeaderLeftAttachment(OdBm::LeaderAttachment::Enum) Sets the left leader attachment position.
Width setLeaderRightAttachment(OdBm::LeaderAttachment::Enum) Sets the right leader attachment position.

In the following example, a text element is created and added to a database:


OdBmCommandContextPtr pDbCmdCtx(pCmdCtx);
OdBmDatabasePtr pDb = pDbCmdCtx->database();
OdBmTextNotePtr pTextNote = OdBmTextNote::createObject();
pTextNote->setOrigin(OdGePoint3d::kOrigin);
pTextNote->setVertAlign(OdBm::VerticalAlignment::Middle);
pTextNote->setHorzAlign(OdBm::HorizontalAlignment::Center);
pTextNote->setDirection(OdGeVector3d::kXAxis);
pTextNote->setRawText(L"Text line 1\nLine2");
pTextNote->setKeepReadable(true);
ODBM_TRANSACTION_BEGIN(tr, pDb);
tr.start();
pDb->addElement(pTextNote);
tr.commit();
ODBM_TRANSACTION_END();
    

See Also

How to Filter Elements

Work with DirectShape Elements

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