I have developed some python scripts to be run when translations are completed. I developed these in PythonWin. I've been pasting the text of these scripts into the "Shutdown Python Script" area under Workspace parameters. Can I call the scripts instead?
Instead of adding a shutdown python script, is it possible to call a python script when the translation has completed?
Best answer by takashi
Hi @angela, if you are looking for a way to run a script defined in an external Python script file when the translation has completed, an easy way is to save your script file (*.py) into the same directory in which you have saved the workspace file (*.fmw), and import it as an module in the shutdown script.
For example, if you have "my_script.py" that contains a function called "my_func()", you can call the function in the shutdown script like this.
import my_script
my_script.my_func()
See here to learn more: Python Documentation > The Python Tutorial > 6. Modules
You can also use a function or class defined in an external file with a PythonCaller.
However, note that the function/class definition has to be conformed to the templates described in the transformer parameter "Python Script". For example, a function that you want to call with a PythonCaller should take a single argument which stores an fmeobject.FMEFeature object.
# my_script.py
def my_func(feature):
# do something
pass
PythonCaller parameters:
- Python Script: import my_script
- Class or Function to Process Features: my_script.my_func
Hope this helps.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.