Skip to main content
Solved

Set writer output folder from attribute value


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.

View original
Did this help you find an answer to your question?

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
jeroenstiers wrote:

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
jeroenstiers wrote:

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+16
  • Supporter
  • March 24, 2017
jneujens wrote:

 

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...

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings