Creates features using the Python script supplied, and sends them into the workspace for processing. The Python script must be in the form of a Python class, with the code responsible for creating the features located in the close() method.
Features are created via the FME Objects Python API.
The example below creates a random number of features, between 0 and 9.
import fmeobjects
import random
class FeatureCreator(object):
def __init__(self):
self.number = random.random()
def close(self):
for i in range(1, int(self.number*10)):
feature = fmeobjects.FMEFeature()
feature.setAttribute("feature_count", i)
self.pyoutput(feature)
A PythonCreator transformer can call scripts stored in the transformer itself or stored globally for the entire workspace:
If you are using extensive Python libraries that you do not want to store inside a workspace: to avoid duplication, you can access .py files on the file system using Python’s import command. In addition to the standard Python module locations, FME will also search the location of the workspace for an imported Python module.
This is the Python script to be executed. If the Python script is stored as the Startup Python Script for the workspace (as described above in Script Editing) you can leave this parameter blank.
The name of the Python Class within the script that PythonCreator will use to begin execution. For the above example, set this parameter to FeatureCreator.
Exposes any attributes that are created by the Python script being executed so they can be used by other transformers.
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
An FME installation includes a Python version 2.7 and Python version 3.5 interpreter. The default Python interpreter used for Python processing is the Python 2.7 interpreter. The FME Objects Python API supports Python 2.7, Python 3.4, and Python 3.5.
The Python interpreter used by FME to execute Python scripts is controlled by the Python Compatibility workspace parameter and the Preferred Python Interpreter setting under Tools > FME Options > Translation.
Python Compatibility specifies the version of Python with which Python scripts are compatible. FME loads the Preferred Python Interpreter if it is compatible with the Python Compatibility. If not, FME loads an appropriate Python interpreter matching Python Compatibility.
For more information, see the FME Workbench help.
If you would like to install a third-party package for use by Python in FME, see Installing Python Packages to FME Desktop in the FME Workbench help.
FME Professional edition and above
Associated FME function or factory: PythonFactory
Search for samples and information about this transformer on the FME Knowledge Center.