You are here: InfrastructurePythonCreator

PythonCreator

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. To view the API documentation, navigate to your FME installation folder and go to this location: fmeobjects\python\apidoc\index.html.

Example Class

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)

Script Editing

A PythonCreator transformer can call scripts stored in the transformer itself or stored globally for the entire workspace:

  • To store a Python script with a specific PythonCreator transformer, use the “Python Script” property of the transformer.
  • To store a Python script globally, click the Advanced Workspace Parameter in the Navigator, and double-click Startup Python Script. Storing scripts globally has the advantage of keeping your Python logic centralized, which makes editing and maintenance easier. This is useful if you want to have multiple PythonCreator transformers throughout your workspace that use the same script. For more information, see Startup and Shutdown Python Scripts in the FME Workbench help.

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.

Parameters

Editing Transformer Parameters

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.

Transformer Categories

Infrastructure

Dependencies

The Python interpreter that FME uses for Python processing is determined under Tools > FME Options > Translation, under 'Python Interpreter'. You can specify a default interpreter, or point FME to a custom interpreter. For more information, see the FME Workbench help.

FME Licensing Level

FME Professional edition and above

Search FME Knowledge Center

Search for samples and information about this transformer on the FME Knowledge Center.