Skip to main content

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 ?

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.


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.

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

 


 

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

 

 


Reply