Activities
latest
false
- Overview
- Cryptography
- Database
- Java
- Python
- WebAPI
Developer Activities
Last updated Apr 2, 2024
Invoking a Python Script
To exemplify how to use this activity pack, we have built an automation process to invoke a Python script which defines two
operations, Add and Subtract. One of the methods, Add, is then called from the script and given a list of integer variables as input parameters. The result, stored in a proprietary
PythonObject
variable, is then converted into a .NET datatype to be further used in Studio.
Note: The Python version you want to use has to be installed on the machine you want to run the process on.
This is how the demo can be built:
- Open Studio and start a new Process.
- Drag a Python Scope activity to the Workflow Designer.
- Specify the installation directory of Python in the Path property of the Python Scope activity. By default, the location is
%LOCALAPPDATA%\Programs\Python\PythonXX\python.exe
, whereXX
is the Python version you are using. - Drag a Load Python Script activity in the Do section of the Python Scope and add the file path to the
MathOperations.py
Python script in the File property. - Create a new
PythonObject
variable, calledMathFunctions
and add it into the Result property field. -
Add an Invoke Python Method activity and configure its properties as follows:
- Input Parameters -
{2,3}
- Instance - Add the variable created at step 5,
MathFunctions
, to this field. - Name - Add the name of the method inside the script you want to use, in this case
add
. - Result - Create a new
PythonObject
variable, calledSumResultPython
, and add it to this property field.
- Input Parameters -
-
Next, drag a Get Python Object activity to the workflow. Configure its properties as follows:
- Python Object - Add the
SumResultPython
variable to this field. - TypeArgument - Select
Int32
from the drop-down list. - Result - Create a new
Int32
variable, calledResult
and add it to this field.
- Python Object - Add the
-
Add a Message Box activity at the end of the project and configure it to display the
Result
variable.Your project should look like this:
-
Run the process. The Message Box displays the result of the Add method.