Skip to main content
Solved

Set writer output folder from attribute value

  • March 23, 2017
  • 4 replies
  • 203 views

nmatton
Contributor
Forum|alt.badge.img+4

Hello FME's geeks !

I am looking for writing outputs as shapefile to a path that is derived from the concatenation of an input parameters, a given string and a timestamp.

In other words, the path should look like $(input_parameter1)/$(string)-$(TimeStamp)

In my case,

  • The input parameter is a folder given by user (Main_Input_Folder)
  • The string is the basename of an input file given by the user without extention (eg : C:\inputFolder\myfile.shp => basename = myfile)

For now, I am able to concatenate the input parameter and the Timestamp (creating a Python scripted private parameter for creating the string) giving something like  $(input_parameter1)/$(TimeStamp) and use it to the "Destination Esri Shapefile Folder" parameter :

0684Q00000ArARXQA3.png

 

However, to add the basename, I created another Python scripted private parameter to extract the basename (used code below) but when I try to add it to the "Destination Esri Shapefile Folder" parameter I get this error : 

Undefined macro `AOI_basebame' dereferenced in file `C:\Data\NMA_dev\FME\wb-xlate-1490276784373_9148'
Program TerminatingTranslation FAILED.

Python script to create the "AOI_basename" parameter : 

import os import ntpath import fme os.path.splitext(ntpath.basename(fme.macroValues['AOI']))[0]

I tried another solution to use a creator>AttributeCreator and add an attribute "OutFolder" with the full path but I can't find a way to use an attribute value as destination folder of shapefile.

PS : the Output_Folder private parameter you see on the picture does not raise error but give results without the AOI_basename, ie C:\outputfolder\-20170323-1200 (where Main_Output_folder = 

C:\outputfolder\ and DateTime = 20170323-1200)

Any idea ?

Best answer by jeroenstiers

Hi nmatton.

Do you have to create the parameter with a python script? The directory (MAIN_OUTPUT_FOLDER) should be used as the location of where to store the output. The filename can be changed using the Fanout option in the writer (link the attribute to the filename).

 

So you just have to create an attribute which contains the string you want to use as a filename.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

Forum|alt.badge.img+7
  • Best Answer
  • March 23, 2017

Hi nmatton.

Do you have to create the parameter with a python script? The directory (MAIN_OUTPUT_FOLDER) should be used as the location of where to store the output. The filename can be changed using the Fanout option in the writer (link the attribute to the filename).

 

So you just have to create an attribute which contains the string you want to use as a filename.


jneujens
Forum|alt.badge.img
  • March 23, 2017

Hi nmatton.

Do you have to create the parameter with a python script? The directory (MAIN_OUTPUT_FOLDER) should be used as the location of where to store the output. The filename can be changed using the Fanout option in the writer (link the attribute to the filename).

 

So you just have to create an attribute which contains the string you want to use as a filename.

 

In the fanout expression just put '@Value(filename)-@Timestamp(^Y^m^d^H^M^S)' to get the date in your filename.

nmatton
Contributor
Forum|alt.badge.img+4
  • Author
  • Contributor
  • March 24, 2017

Hi nmatton.

Do you have to create the parameter with a python script? The directory (MAIN_OUTPUT_FOLDER) should be used as the location of where to store the output. The filename can be changed using the Fanout option in the writer (link the attribute to the filename).

 

So you just have to create an attribute which contains the string you want to use as a filename.

 

Great ! thanks for this quick answer !

 

To be complete, I missed the difference between folder/file based writer. In this situation, filename have a fixed definition but output folder is updated following the inputs parameters. Tests showed that is not possible to create a sub-dir from the fanout, but it is using the destination folder parameter.

 

So the real issue here is that the 'return' statement had to be addded on the python script...

 


itay
Supporter
Forum|alt.badge.img+18
  • Supporter
  • March 24, 2017

 

In the fanout expression just put '@Value(filename)-@Timestamp(^Y^m^d^H^M^S)' to get the date in your filename.
Would be my choice too, easier to manage in the future...