Hi Damian, can you share your PythonCaller input? Also: do you want to run your .py for every feature that passes onto your PythonCaller, or do you have to run it only once per translation. If the latter: in the Navigator window you can set a Python shutdown/startup script (under Workspace Parameters > Scripting).
Try something like the following in your PythonCaller:
import fmeobjects
import my_python_file
def FeatureProcessor(feature):
my_python_file.my_function(feature)
This will call my_function() in the external Python file “my_python_file.py” for each incoming feature. The incoming feature, of type fmeobjects.FMEFeature, will be passed as a parameter.
Dear @joepk, @david_r , thank you for your responses.
@joepk, I only need to run my .py script once per translation. I have indeed successfully used the python startup script to run my file, however, i don’t need to execute my .py file every time I run my FME script. My preference is to use workspace parameters with user input so that I can choose when to run the .py file (not essential, but nice to have - my python script updates an external JPG map, but the map doesn’t need to be updated every time I run the FME script, only sometimes). My python caller input is below.
@david_r, thank you very much for your suggestion but my python caller doesn’t have any incoming features (described above).
Regards, Damian
import os
def run_script(script_path):
# Execute the script using execfile
exec(open(script_path, 'r').read())
script_to_run = "Q:\AoAM\Outputs\Images\JPGMap.py"
# Run the script
run_script(script_to_run)
If you do not want to run your python script every time you run this workspace and if it is not triggered by any event in your workspace, I would either omit it from the workspace and run it ‘manually’ or I would try to get the requirements for having to run the script into the workspace, in order to trigger it.