Overview
FrameworX takes the Python integration to the next level, with an unique set of features:
- Multiple Python Versions: Support for different Python versions.
- In-Solution Designer Editing: Edit and test Python scripts within the Designer,
- Tag Direct Access: Python can access real-time tags, Historian tables, and all modules namespaces.
- .NET Integration:: Python can call methods in C# or VB.Net, and vice versa.
- Web Integration: Web pages can use Python classes from the server.
- Extensibility Toolkit Allows external Python applications to interface with FrameworX servers.
On this page:
Installation and Setup
The .NET integration is currently compatible and tested with Python releases 3.7 - 3.11. While earlier and newer versions may work with most features, they are not officially tested or supported.
Setup Steps:
1. Install Python on the machines where you run the application and on those using the Solution Designer.
2. Configure the Solution Settings to select the appropriate Python shell folder.
Each solution can specify its Python interpreter, facilitating the development and maintenance of different solutions that may require different Python versions.
Once you've installed Python, you can take a look at our Python demo with code examples.
→ Learn more at Python Integration Demo.
Using Python in the Solution
The Python code can used at:
Displays Code Behind and Graphical Elements
Scripts Tasks and Classes
- Script-Tasks: event driven or periodical tasks, running in the server computer.
- Script Classes: library of methods and functions that be used in both server and client machines, and by Python, C# or VB.Net Code.
Displays CodeBehind and Graphical Elements
- Displays CodeBehind: The entry point for the CodeBehind, is a .NET method, but right o first line you can call a Python class sro run the logic
- Graphical Elements and Actions: When definition the dynamic behavior of the Graphical Elements, the Action and the CodeBehind dynamics do asynchronous calla to server methods, which can be in Python.
Shell Integration
- Shell Integration: executing Python code from external files.
# This code call the execution of the external file using Python Shell # with the optional args defined in this initial section # # The macro _ExecutionPath_ is replaced by the path where the solution is set to execute # Replace that macro by a specific path, or user other built-in macros as nedded # arg1 = @Tag.Tag1 arg2 = @Tag.Tag2 result = TK.ExecutePythonShell("_ExecutionPath_ExternalSum.py", [arg1, arg2]) @Tag.Result = result
Designer Python Code Editor
Code Editor User Interface
The code editor is accessed at the Designer Scripts → Code Editor page
Testing the code
When the editor is used Script Tasks, you can test the scripts directly, using the Play button at the Task name line..The console standard output is redirection to the Designer output panel, showing the results of your code.
Accessing Tags and Modules properties
The access to Tags and other properties for other models is exactly the same as C# or VB.Net, just use the '@ symbol to access directly the properties, as shown in the image.''@tag.Tag1
.NET Interoperability
Calling ScriptClass Methods
At the Script namespace, any code in your solution, call call methods defined on the script classes.
@Script.Class.TestClass.ExempleMethod(param1, param2)
This activation is independent from the language the class was creating. Meaning C# and VB.NET can call Python classes, and Python code call .NET classes.
In this section: