Reading and Writing AutoCAD Text & MText Features

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2017.x

Introduction

Text features, or labels, can be tricky to work with when translating between different formats, especially if you want to try and preserve some of the richer formattings like fonts, size, curved words and paragraph structure. In this article, we will look at how FME handles AutoCAD text features and explore some real-word examples. 

It is important to note that when inspecting AutoCAD data with the FME Data Inspector it will almost always look different to how it is displayed in your Autodesk application (especially text). As with all DWG transformations, it is strongly recommended that you view and verify any output DWG files with an applicable Autodesk application. Don't have one? You can use Autodesk's fantastic free online 360 Viewer.

This article will look at AutoCAD entities of type: autocad_text and autocad_multi_text.

 

Two text formats

If you are familiar with AutoCAD you’ll likely be aware that there are two main options available for creating text features in your DWG:

  • Text (or Single Line); and
  • MText (or Multiline-text)

autocad-text.pngmtext-text.png

MText and Text features or entities as seen in AutoCAD 2017: Each simple text feature can only contain a single line whereas the MText feature includes all three lines.

Text is simple, single line text features with few properties. There are several things we can do with simple text in AutoCAD such as move, scale, rotate and stretch our words, however, we are somewhat limited in terms of style and each new line of text becomes a new feature. Simple text would not be used for writing larger blocks of text.

MText features provide extra functionality, they can contain multiple lines of text and they have the ability to contain several different fonts and styles within the same feature. In AutoCAD, MText features behave how you would expect typical word processors to behave.

OK, we’ve covered off AutoCAD, now let’s look at how FME represents these different features.
 

Simple Text

All text features from DWG files are represented geographically by point geometry (including MText). This point is determined by the text insertion point. When reading text features from DWG, the most popular text properties (such as size (height), rotation and string contents) are copied and converted to FME format attributes. These FME attributes are what the FME Data Inspector uses to visualise the features.

Note: There are a number of AutoCAD specific format attributes which are not recognised by the FME Data Inspector and is the reason why your DWG might look different in FME and AutoCAD. These attributes can be identified by the ‘autocad_’ prefix and can be found in the Format Attribute window on the right-hand side of the FME Data Inspector. Each of the attributes can be modified with FME but will only be recognised by the AutoCAD writers. More about AutoCAD format attributes here.

Some interesting AutoCAD specific text attributes which are not recognised by the FME Data Inspector, but can still be modified include:

  • Obliquing (autocad_oblique);
  • Justification (autocad_justification);
  • Width Factor (autocad_width_factor); and
  • Text Style (autocad_shape_name)

For a full list of AutoCAD specific format attributes which are applicable to Text features, check out the Help Documentation here.
 

Examples

Example 1: Geodatabase attributes to text DWG labels

Before we get started on MText, let’s take a look at a simple text example in FME Workbench. Let’s convert some roads (attributed line features) from a geodatabase into a DWG file, and try to represent some of the attributes as simple labels in our output DWG and see what happens.

1. Download and open example1.fmwt:

  • If we inspect the source Feature Type with the FME Data Inspector we can see that we have line features representing the roads of Vancouver’s West End. Take a look at the attributes in the table - the workspace will use these to create labels from them. In the workspace, you will see that there is a Labeller and an AttributeManager (below). You should also take note that there are two data streams going in the output 'Roads' Feature Type.
  • The Labeller is being used here to create and position labels based on an expression which combines the values of two attributes on each road. The Labeller will replace the line geometry with positioned text geometry.
  • The AttributeManager is being used to remove unneeded attributes and also to create and set a new attribute called autocad_oblique. This attribute will be used by the AutoCAD writer to make the text look italicised.

example1.pngExample 1 reads in the Roads feature type from our geodatabase and uses the Labeller to create two line labels from StreetId and StreetName. It uses an AttributeManager to create and set the ‘autocad_oblique’ attribute and then finally writes out the roads and labels into a single Roads layer in our output DWG. Inspectors are placed just prior to the writer. Run the workspace and wait for the FME Data Inspector to load up. Zoom into one of the road labels and you will notice that the labels are displayed as two lines of text that are stored as a single text feature.

2. Run the workspace and wait for the FME Data Inspector to load up. Zoom into one of the road labels and you will notice that the labels are displayed as two lines of text that are stored as a single text feature.

3. Take a look at what has happened to the features after they were written out by the ACAD writer: Locate the Output.dwg file and open it in AutoCAD. You will notice that the two lines of text have been split out and written as two separate text entities. We can also verify that the text is also now oblique.

twoentities.png

Output.dwg as seen in AutoCAD 2017: Each of the lines of text from our labels have been converted to single simple text entities, we can verify that the text features are also obliquing by a factor of 15 as was set in the AttributeManager.
 

MText

OK now we’re getting into the more challenging stuff. We’ve looked at simple text, so what about MText?

MText (or multi-text) is an AutoCAD entity type: autocad_multi_text) which can handle richer formatting than the simple autocad_text entity. Formatting options include the ability to have multiple lines, multiple fonts, text wrapping, and bullet points, all within a single feature. FME can both read and write AutoCAD MText features, however, as with most AutoCAD entities, the appearance of such features will be different when viewed with the FME Data Inspector.

Reading MText: Explode, or not to explode? That is the question

When adding a DWG reader to a workspace (and even when viewing features in the FME Data Inspector) it is always important to check the reader parameters. This is especially true when working with MText entities. When reading MText entities with FME, a user can choose to either explode their MText features into individual text entities (similar to exploding blocks which is covered in this article), or keep the MText feature as one.

This option can be found in the reader parameters in the Entity Options section (see below). Choosing to explode your MText entities will split out each of the lines of text into separate text entities (this is the default). If you want to keep your MText as a single entity be sure to uncheck this box.

readerparameters.png

REALDWG reader default parameters: note that Explode MText Entities is selected by default.


Unexploded

When an unexploded MText feature is read into FME it is treated similarly to a simple text feature, however, in order to preserve the richer formatting, additional format attributes are created. The most important one is the autocad_mtext_string because it is the format attribute that carries the formatting code used by AutoCAD. This is important if you are writing out to AutoCAD DWG, which we’ll see in an example below.

When inspecting an unexploded MText feature with multiple lines in the FME Data Inspector, you may notice that it is read as a single line, whereas in AutoCAD it is read as several. This is because the text is wrapped in AutoCAD. The wrapping width is preserved within the format attribute autocad_mtext_ref_rect_width. Check out the FME help for more info on MText specific format attributes.


Exploded

When FME explodes an MText feature it becomes a group of separate autocad_text features which all share the same autocad_entity_handle format attribute. This is handy if you want to edit certain parts and then aggregate them back together.

mtext-compare.png

Exploded vs unexploded MText in the FME Data Inspector: The green text has been exploded by the reader and each of the three lines from the MText entity are now treated as three individual features. The blue MText on the right is unexploded (note that we only see one line here whereas in AutoCAD it appears as three).


Example 2: Creating and Writing MText features to DWG with FME

OK so now we know how to bring in MText features from a DWG file, but you may be asking, “how do I use FME to create cool MText features?”

The easiest way to create MText features is with the DWGStyler transformer. Example 2 shows this with a basic workspace. Example 2 performs a similar transformation to Example 1, however, this time our text will be written out as MText entities.

  1. Download and open example2.fmwt. The source data is exactly the same as example1 above so we can skip the inspection of our geodatabase feature class this time.

     

    example2.pngExample2: This is very similar to example1, however, we have swapped out the AttributeManager for a DWGStyler

  2. Open up the parameters of the DWGStyler to see what parameters have been set. All we have done here is select which type of text we want (Multi-Text), the Font and the Justification. We have left Size, Rotation and Text blank as these have already been created previously by the Labeller transformer. Populating these fields would overwrite what was set by the Labeller. For more help on the DWGSyler check out this article. The DWGStyler is great because it creates all the AutoCAD specific attributes we need without us needing to worry about them. If we didn't have the DWGStyler we would have to create the relevant attributes with an AttributeManager or AttributeCreator.

     

    dwgstyler.png

    DWGStyler parameters: A simple example of how to create MText features. In this example I have left the Text Size, Rotation and Text fields empty because the Labeller has already done this part for us. All we want the DWGStyler to do in this case is prepare the features so that the writer knows to save them as MText.

  3. Run the workspace and wait for the FME Data Inspector to load up. Zoom in and select one of the text features and examine the format attributes. This time you will see three autocad_* attributes which were created by the DWGStyler:
autocad_attach_point (encoded: utf-8)	autocad_middle_center
autocad_entity (encoded: utf-8)		autocad_multi_text
autocad_mtext_string (encoded: utf-8)	{\fTimes New Roman|b0|i0;Pendrell StID: 11418}

**IMPORTANT** Remember to open up the result (Output_mtext.dwg) in AutoCAD to see the proper representation. Zoom in on a label and you will see that each is a single, two line MText entity centred on a road. The justification was set in the DWGStyler. For more information on justification check out this article.

oneentity.png

Text in AutoCAD: The result of example2 as seen in AutoCAD, a single MText entity centered on a road.

 

 

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.