Give Your DWG Some Style: Using the DWGStyler, template files, blocks and more

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

There are several ways to style a DWG file with FME. The most common methods are by either implementing the use of the DWGStyler transformer, setting the Layer Properties in the writer or by leveraging an existing template DWG file. This article touches on each method and includes a few examples for download so you can experiment for yourself.

Before we get started there are a few considerations to note when working with DWG files, and in particular, differences in how FME and AutoCAD represent styles. Namely, the FME Data Inspector is limited in the way it displays lines. It can only display line color, but not line type or line weight, etc. The FME Data Inspector also will not display any area fill patterns (e.g., hatches). As with almost all DWG translations, it is therefore strongly recommended that you inspect your output data in AutoCAD. That being said, just because the FME Data Inspector does not display these details, the properties are still there. You can see AutoCAD specific properties in the format attributes for a given feature (in the right-hand Feature Information window).

It is important to note that when a DWG file is written with one of the DWG writers the writer looks for and makes use of AutoCAD specific format attributes. These can be identified by the “autocad_” prefix.

For more information on how FME represents DWG features check out this section of the FME documentation.

 

What is a Template DWG File?

Whenever you would like more control over the appearance and state of the various layers in your output DWG file, it is highly recommended that you leverage the use of a template DWG file. A template is an existing DWG file that contains the line-styles, layer properties, or blocks etc. that you would like to be applied in your written product. This template can be applied in two places: in the writer (in the navigator pane, under 'Template File'), and in the DWGStyler transformer. When using a template file in the DWGStyler it is essential to also include the template in your writer, this is discussed further below.

cadparams.png

A template DWG file has been chosen as a parameter within the ACAD writer.
 

Setting Layer Properties

The default Layer Properties of a DWG file can be set in FME when writing out a DWG file. There are two simple ways to assign these:

  • By defining them in the Format Parameters in the output Feature Type.
  • By using a template file with Layer Properties already defined.

 

Examples

Example 1: Setting Layer Properties in the DWG output feature type (without a template file)

If you do not have a template file with Layer Properties already defined, then the simplest method of setting styles for a DWG is by adjusting the Feature Type Properties in the output feature type. This is demonstrated in the first example workspace (example1.fmwt) .

 

On the output, DWG Feature Type, open up the Feature Type Properties by double-clicking on the output feature type then choose the Format Parameters tab with the green cog. Here you can set your AutoCAD layers properties (Note in FME Workbench 2017 the Format Parameters can be found in the General tab). Layer Properties will only apply to features that do not already have a color assigned to them.

layersettings.png

This screenshot shows the default settings of the DWG writers format parameters. A color value of 10 corresponds to Red in AutoCAD. Without a template file with a different Linetype defined you will not be able to change the Default Linetype here.

example1result.png

The output of example one as seen in AutoCAD 2017. When the workspace is run we get an output of red, green and blue road lines. If we open up the Layer Properties we can verify where and how our settings have been applied.
 

Example 2: Setting Layer Properties in the DWG output feature type (with a template file)

If you already have a DWG file that contains layers with styles that are already defined, such as the one in the template.dwg , then FME lets you leverage these properties by using it as a template file.

To add a template file to a DWG writer, find the template file parameter in the Navigator pane on the left. For a template file to work correctly you will need to ensure that your layer names in your template DWG file match the output layer names in your workspace.

This is demonstrated in example2.fmwt .
 

Example 2 looks identical on the surface to example 1, however, our ACAD writer now has a template DWG file defined. The template DWG file already has the layers Roads-Arterial and Roads-Residential predefined (see below). We no longer need to manually set the layer properties for each of these outgoing feature types. Notice though that our template does not define Roads-Other. Roads-Other will work just as it did in example one, open up the Format Parameters in Roads-Other to see what Layer Properties we can expect.

IMPORTANT: When you are using a template while writing a DWG, the writer will ignore any Layer Properties you have manually set in the writer if the feature type name matches a layer name in the template file.

 

templatefile.png

Adding a template file to your ACAD writer through the navigator.

cadlayerprop.png

Layer Properties in the attached template file as viewed in AutoCAD 2017. Here we can see that the layers titled Roads-Arterial and Roads-Residential (and 0) both have defined styles. These properties will be copied to the output DWG file.

example2output.png

The output of example two as seen in AutoCAD 2017. When the workspace is run we get an output of red, green and blue road lines just as we did in example one. If we open up the Layer Properties we can verify that the Layer Properties from our template file have been applied.
 

The DWGStyler Transformer

If you want more control over your default layer properties, then applying a template DWG to the writer is one of the best ways to achieve your desired output. The DWGStyler's role, however, is to provide an opportunity to make some additional alterations to the properties at a feature level as opposed to a layer level (or feature type level).

 

The DWGStyler lets you modify the appearance of blocks, texts, lines and various area features of your data set. If you use AutoCAD then the parameters in the DWGStyler should look somewhat familiar. Not all DWGStyler’s parameters are covered in this article, if you are interested in learning more, check out the DWGStyler documentation.

 

As with the DWG file writers, the DWGStyler also lets you leverage an existing template file. When you apply a template to the DWGStyler, however, this will not affect the output, but rather it allows you to access block libraries, line-styles or other custom attributes that are defined within the template. This is very useful when you want to create or modify blocks from an original template library or change the appearance of certain layers to better suit your output DWG (e.g. block rotation and scale, line-styles or custom fill patterns).

 

Below are two examples that use the DWGStyler. The first one (example3.fmwt) uses the transformer to give fonts and colors to text labels, the second example (example4.fmwt) uses a template file to turn point features into predefined blocks.

 

Example 3: Using the DWGStyler (without a template file)

As mentioned above, using the DWGStyler will assign styles to your dataset at a feature level, we can, therefore, style different features and save them all as one layer. The DWGStyler can also style multiple geometries at the same time so there’s no need to separate out geometries.

In example three, we have used the DWGStyler to color different “RoadTypes” from a geodatabase. At the same time some text features, which get created in the workspace by a labeller, are also getting styled. Once the features have been styled they are merged back into a single layer in our DWG output. Our output DWG will contain labelled roads with different styles all in a single layer.

 

example3.png

Example three - download the workspace here

example3output.png

A close-up view of the output from example three as seen in AutoCAD 2017 so we can see the labels.


Example 4: Using the DWGStyler to create blocks (with a template file)

While FME is capable of creating AutoCAD blocks, it is a lot easier and quicker to use predefined blocks from a template file.

When you apply a template file to the DWGStyler, this will not affect the output as shown in the previous examples, but rather it allows you to access the block libraries, line-styles and other custom formats contained within the template. This is very helpful for when you want to either create predefined blocks from point features or change the appearance of certain features to align with any custom styles.

Download and examine example4.fmwt. In this example, with the help of the DWGStyler, we quickly convert our point features from a geodatabase into blocks that are already predefined in our template file. StreetLights and TrafficSignals are each given their own respective block definitions thanks to the DWGStyler and are then merged into a single layer called Lights. If we open up our output in AutoCAD we can see that what was once boring old points are now funky blocks!

**IMPORTANT** If you are using a template file in a DWGStyler to define blocks then you will also need to include the same template file in your DWG writer. After features pass through the DWGStyler they are still represented in FME as point features, however, the features will now have additional format attributes including autocad_block_name. When the writer encounters these attributes it will look in the template file to find a match. If no template exists in the writer then by default these features are rejected and they will not be written.

workspaceoverview2.png

Example 4: Creating blocks with the DWGStyler. In this example, we use the DWGStyler with a template file to assign our input points with some funky blocks. In the example, some simple labels have been created from an applicable attribute with the help of the LabelPonitReplacer and the Offsetter. The labels and point features are all written to the same layer in our output DWG. Upon writing, the points are converted to the respective blocks with the help of the template file in the writer. You may notice that the labels did not pass through a DWGStyler, they will adopt the default Layer Properties which were set using the method in outlined Example 1 above.

 

dwgstyler.png

DWGstyler Blocks parameters: with the Blocks box checked and a template file in use as shown here, we can click on the highlighted ellipses to access any blocks defined in the template. In this case we have two blocks ‘Light’ and ‘Signal’. Here we could have also chosen to scale or rotate the blocks.

example4output.png

A zoomed in view of the output of example four as viewed in AutoCAD 2017. In this view, we can see labelled Light blocks surrounding a Signal block.

 

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.