InvokeModule(ModuleId: String; FunctionName: String; Params: Array): Variant;
InvokeModule(ModuleId: String; FunctionName: String; paramarray Params: Array of Object): Object;
ModuleId. Module identifier with code in the Python language in repository.
FunctionName. Name of executed function. The name is case-sensitive.
Params. Array of parameter values that must be sent to executed function.
The InvokeModule method executes function in the Python language stored in the repository module and returns result of its work.
If the executed function does not contain input parameters, do not specify Params (In Fore.NET specify the New Object[0] empty array). Values of parameters in Params can be sent as a separate array or enumerated via a comma. Simple type values, such as, String, Char, Integer, Double, Decimal, Currency, Boolean (types str, int, float, bool in Python), are sent according to Fore syntax without transformations. The Null value corresponds to the None value in the Python language. If a Python function receives an object of some Python class, list, or tuple as an input parameter, create the corresponding object using the Fore class: PythonClassObject, PythonList, PythonTuple.
If the function has parameters with default values, and it is required to send only part of parameters, use named parameters. Named parameters are implemented by the PythonParameter class. Create parameters with required names, set value for them and send them to the Invoke method.
Executing the example requires that the repository contains a Python module with the MOD_PYT identifier. The following class is implemented in the module:
def summXY(x, y):
return x + y
Add links to the Metabase, Python system assemblies.
Sub UserProc;
Var
pUtils: IPythonUtils;
Result: Variant;
Begin
pUtils := New PythonUtils.Create;
Result := pUtils.InvokeModule("MOD_PYT", "summXY", 100, 500);
Debug.WriteLine(Result);
End Sub UserProc;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Python;
Public Shared Sub Main(Params: StartParams);
Var
RunContext: ForeRuntimeContext;
pUtils: IPythonUtils = New PythonUtilsClass();
Result: object;
Begin
RunContext := (Params.Metabase As IForeServices).GetRuntime().Context;
Result := pUtils.InvokeModule(RunContext, "MOD_PYT", "summXY", 100, 500);
System.Diagnostics.Debug.WriteLine(Result);
End Sub;
On executing the example a function in the Python language is executed that sums two numbers sent in parameters. The result of function execution is displayed in the development environment console.
See also: