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?
How about swapping from using a writer to using a FeatureWriter transformer instead, that means you can now write out the data and then have a PythonCaller immediately after the FeatureWriter to initiate your script. That should avoid the need for the shutdown script.
How about swapping from using a writer to using a FeatureWriter transformer instead, that means you can now write out the data and then have a PythonCaller immediately after the FeatureWriter to initiate your script. That should avoid the need for the shutdown script.
Hi @angela,
According the good tip that @1spatialdave wrote, the transformer PythonCaller can it use .
About the how use the PythonCaller has a serie interesting Link:
1) PythonCaller User Parameters
Thanks,
Danilo
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.
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.
import sys
sys.path.append('C:/scripts')
import my_script
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.
you can use SystemCaller instead of the PythonCaller and run a command similar to:
C:\Python27\python.exe C:\Users\Username\Desktop\my_python_script.py