Creating Text Elements in Teigha BIM

Alexander Geniatov

November 02, 2017

To create text elements in a document, create an OdBmTextNote class object and add it to the database.

Text notes are created and registered in the database with the usual element interfaces; you only need to define text-specific data. These are the main properties that define text elements:

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

This data can be set with the following interfaces:

  • setOwnerDBViewId(OdBmObjectId) — Interface is inherited from Element and defines the view the text element is created on. The view ID must not be changed after adding the element to the database.
  • setRawText(OdString&) — Sets text from a raw text string.
  • setRtfText(OdAnsiString&) — Sets text from an RTF text string.
  • 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.
  • setVertAlign(OdBm::VerticalAlignment::Enum) — Sets the vertical alignment.
  • setHorzAlign(OdBm::HorizontalAlignment::Enum) — Sets the horizontal alignment.
  • 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.
  • setWidth(double) — Sets the width of the text. If this width is smaller than the width of the text on one line, the text will be wrapped.
  • 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.
  • setType(OdBmObjectId) — Sets the text note type ID. The ID parameter must point to an OdBmTextNoteAttributes object, otherwise the method returns an eInvalidInput error.
  • setLeaderLeftAttachment(OdBm::LeaderAttachment::Enum) — Sets the left leader attachment position.
  • setLeaderRightAttachment(OdBm::LeaderAttachment::Enum) — Sets the right leader attachment position.

Default values

Besides the text, all other properties are optional. If you don’t set them before adding a text element to the database, they are filled with the default values:

  • View ID is set to the ID of the active view.
  • Origin is set to (0, 0, 0).
  • Text alignment is set to left/top.
  • Direction is set to the view right direction.
  • Width is set to the width of the text without wrapping.
  • Left leader attachment is set to the top line.
  • Right leader attachment is set to the bottom line.

Example

OdBmTextNotePtr pTextNote3 = OdBmTextNote::createObject();
zpTextNote3->setOrigin(OdGePoint3d::kOrigin);
pTextNote3->setVertAlign(OdBm::VerticalAlignment::Middle);
pTextNote3->setHorzAlign(OdBm::HorizontalAlignment::Center);
pTextNote3->setDirection(OdGeVector3d::kXAxis);
pTextNote3->setRawText(L"Text line 1\nLine2");
pTextNote3->setKeepReadable(true);
pDb->addElement(pTextNote3);