Extract Layers from Traits and Swap Appearances

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2018.x

Introduction

This example demonstrates how to restore the original layers of the SketchUp file and how to represent them properly in a 3D PDF document. Since the Adobe PDF Reader supports layers and has the capability to show and hide them in the model tree, it can be very useful to preserve this structural aspect of the data.

The attached template workspace performs a SketchUp to 3D PDF translation. Download the template and open it up in FME Workbench. A closer look at the source SketchUp file reveals three different layer names. Layer 0 represents the terrain, Layer 1 represents buildings with heights below 40m and are colored red, and Layer 2 represents buildings taller than 40m, which are colored blue. This conditional layering is based on a previous example.

 

SketchUp File Structure What the Layer Represents
Layer 0 Terrain
Layer 1 Short buildings, red
Layer 2 Tall buildings, blue

There are three SketchUp layers in the source file. They represent three groups of data, the terrain, the short buildings, and the tall buildings.

 

Step-by-step Instructions

1. Read SketchUp File

Reading the SketchUp file results in only one feature because the layers are already merged into a single aggregate feature. In a simple workspace, with one reader and one writer, the resulting 3D PDF would contain only one layer. In this example and the attached template workspace, we will be using a more complex method with transformers to deaggregate, filter, and preserve the original SketchUp layers in the PDF output. The result will be a PDF document with three layers.

 

feature-information.png

The Feature Information dialogue in the Data Inspector of the SketchUp file. You can see that although it reads it as one feature, the layer names are still stored in the aggregates of the source file.

 

2. Extract SketchUp Layer Names

To restore the layers, the layer names need to be extracted so that we can filter the geometries based on the different layers. If we read a SketchUp file with FME, we can find the layer names as a trait on the IFMEFaces geometry within the IFMEAggregate feature.

 

2.1 Break Up Aggregate Features using the Deaggregator

We will use the Deaggregator to split up the one aggregate feature into its components so that we can filter them into their proper layers later. Notice that we are using the Mode: ‘Flatten One Level’. This means that it will break up the source feature (the parts in the IFMEAggregate) by one level of aggregation, which then yields all the individual features seen in the output model in PDF later.

 

simple-translation.png

The template workspace provided of the SKP to 3D PDF translation. Notice that one feature goes into the Deaggregator and 9692 features come out, broken down by one level.

 

2.2 Extract the SketchUp Layer Names: GeometryPropertyExtractor

Next, the GeometryPropertyExtractor extracts the layer name into an attribute “sketchup_layer_name" for each feature (note that the GeometryPropertySetter can store this trait as an attribute for every single face).

geom-property-extractor.png

The parameters for the GeometryPropertyExtractor. We want to extract the layer names from the SketchUp file. The GeometryXQuery is displayed below and is set to the IFMEFace, which is where the layer names are stored.

 

1geom-xquery.png

The expression for the Geometry XQuery in the GeometryPropertyExtractor transformer. It is set to IFMEFace, where the layer names are stored.

 

When you have set the Test Clauses, your Geometry Part XQuery Preview should look like:

for $geom in //geometry
where $geom/@fme_geometry_type = 'IFMEFace'
return number($geom/@fme_id)


If you would like to view the output at this point, run the workspace with feature caching on, then go to the GeometryPropertyExtractor to inspect the Extracted output port. You will now notice that the table shows you 3 columns- the third being the sketchup_layer_name, where features are either part of layer 0, 1, or 2.

 

2.3 Filter The SketchUp Layers using the TestFilter

Finally, the TestFilter separates the three different layers from each other.

  Test Condition Output Port
If @Value(sketchup_layer_name) = Layer0 Layer0
Else If @Value(sketchup_layer_name) = Layer1 Layer1
Else If @Value(sketchup_layer_name) = Layer2 Layer2

test-conditions-caseinsensitive.png

When you are setting test conditions, be sure to go into the Mode column for each condition, and select ‘Case-Insensitive’.

Be sure to go into the test conditions in the TestFilter parameters and set Mode to Case Insensitive. You can do this by opening a dialogue in the Test Condition, then under the column ‘Mode’, in the dropdown menu, select ‘Case Insensitive’. This means that the features will pass the test condition regardless of whether the layer name begins with an uppercase or lowercase letter ‘L’.

 

3. Extract Appearances

To demonstrate how to retrieve appearances of features and apply them to other features, the appearances for the buildings are simply swapped in this example. This will happen in two steps: (1) extracting appearance styles using the AppearanceExtractor and the Tester, and then (2) swapping the appearances using AppearanceSetters.

 

In extracting the appearances, we will use two transformers:

  • AppearanceExtractor: to extract all parts from the front and back sides. By appearance, we are referring to the properties of the model like color, texture, transparency, and shininess to name a few. The output of the AppearanceExtractor does not include any geometries. Only appearance parameters or textures are stored in the output features.
  • Tester: Since we have extracted all of the appearance styles, we want to separate them by layers. In the Tester we will test for Layer 2, if it fails, the style then belongs to Layer 1. In other words, the Passed port is Layer 2, and the Failed port is Layer 1.

 

4. Swap Appearances

To swap the appearances it is important to set the ‘Appearance Storage’ in the AppearanceSetter Parameters to: ‘Replace Existing Definitions’.This setting is used to replace the existing appearance stylings in the layer with a new one, allowing it to override existing styles. Since we are swapping the appearances of the buildings, the short buildings (red) will now be blue, while the tall buildings (blue), will now be red. This is done by how we connect the ports.

appearance-swap.png

In the image above, we have connected the features of Layer1 (top left) from the TestFilter to the Geometry port in the AppearanceSetter, and the appearance of Layer 2 from the Tester (bottom left transformer, in the Passed port) to inform the Appearance in the same AppearanceSetter on the top right. The same idea is applied to the second AppearanceSetter, swapping the appearances to that of the feature of the other layer.

 

Another way to picture this is:

SketchUp Layer Name What the Layer Represents Original Appearance New Appearance
Layer 1 Short buildings Red Blue
Layer 2 Tall buildings Blue Red

 

5. Write to 3D PDF

All output layers for the 3D PDF document are represented by a single destination feature type. By using the fanout by attribute option in the destination feature type parameters, feature types can be created based on the sketchup_layer_name attribute from the input.

feature-type-fanout.png

 

6. View the output

3D PDF data is best viewed in Adobe Reader. It’s generally a good idea to keep your Adobe Reader version up to date if you are going to work with 3D datasets.

 

Completed Workspace

workspace-skp-to-pdf.png

 

Results

The result is a 3D PDF with the appearances for tall buildings and short buildings swapped. The buildings with a height greater than 40m are now red, while the buildings shorter than 40m are now blue. Congratulations! You have written out a 3D PDF that preserves the layers of the original SketchUp file. If the Model Tree toolbar in the PDF is not immediately visible when you open the file, right-click on the image and select ‘Show Model Tree’.


http_download_1444329824402_6032.png

 

Data Attribution

The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.