FME_BEGIN_PYTHON

The FME_BEGIN_PYTHON directive specifies a Python script file to execute just prior to the start of translation. The script is executed after the mapping file has been completely parsed, and after the log file has been opened, but before any of the readers or writers have begun to do their processing.

Note  FME will abort the translation if the execution of FME_BEGIN_PYTHON scripts fails. If, for some reason, this behavior is undesirable and you want to continue a translation even if the execution fails, you can use Python's exception handling to trap errors, allowing FME to continue with the translation.

The syntax is:

FME_BEGIN_PYTHON <python script>

where the <python script> is any valid Python script file to execute.

The script may access the following functions and variables in the 'fme' Python module:

Global Function

Description

fme.resolveFMEMacros(value)

Resolve all FME macros in the input string and return the resolved string. FME macros are defined as all character sequences that match the pattern $(<alphanumeric characters including '_'>).

If a matching pattern does not resolve to an FME macro, the matching pattern will remain untouched.

fme.getAbsolutePath(fileName)

Given an input file name or FME macro of a file name, this method will return an absolute path of the file name.

Unless the resolved input file name is an absolute path itself, the absolute path will be determined with the assumption that the input is relative to the executing Workspace.

 

Variable

Contents

fme.logFileName

The name of the log file used for this translation.

Note  Writing custom (user-defined) messages to the log file varies depending on whether it is during the start-up or shutdown phase. In a start-up script (because FME already has the log file open, and it is dangerous to open it more than once), you should use fmeobjects.FMELogFile().

fme.mappingFileId

The value of the MAPPING_FILE_ID directive specified in the mapping file

fme.macroValues

A Python dictionary, indexed by macro name, which holds the value of each macro known within the workspace or mapping file at the end of parsing.

fme.licensing (FME 2013+)

The edition information and FME license type.

Note   To import the 'fme' Python module, execute the statement import fme.