Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

FrameworX takes the Python integration to the next level, with an The platform includes a unique set of features for Python integration:

  • Multiple Python Versions: Support for different Python versions.
  •  InIn-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 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 the platform's servers.

On this page:

Table of Contents
maxLevel3
stylenone


Installation and Setup

The .NET integration is currently compatible and tested with Python Shell integration requires Python releases 3.7 - 3.11. While earlier and newer versions may work with most features, they are not officially tested or supportedonwards and the installation of Python.NET.

Setup Steps:

    1.    Install Python and Python on .NET in 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 own Python interpreter, facilitating the development and maintenance of different solutions that may require different Python versions.

Expand
titleClick here to expand on how to Install Python

You can download Python here.

Check the Use admin privileges checkbox, and select Customize installation.

Image Added

During the installation of the Python Engine, we strongly recommend choosing select the option to “Install for all users”.

If You install Python under your local user, you may have issues when running the solution as a service, or when deploying the solution for production.

Tip

This image may be slightly different for your Python version, but always enable the options equivalent to:

  • Add Python.exe to PATH

Especially in the production server.

  • Install with admin rights to all users,
  • Customize the installation to installation in the Program Files, instead of Users folder


Once you've downloaded, open the command prompt as an ADMINISTRATOR and type “pip install pythonnet”. For this work, you'll need internet access. If internet is not available, download and install manually.

Once Python.NET has been installed, you can then start using Python in your solution.

Note

Note: For Python versions above 3.12, Pythonnet is not available. For more information, visit their documentation.



Expand
titleClick here to expand on how the setup the Python location in the Designer

Go to Solution / Settings tab and locate for the Python GroupBoxInterpreter box. Click the "..." button, navigate to find the installed Python Engine, and select the python.exe file.

Python Interpreter

Local

Defines the path for of the Python installation folder on the local machine.

Server

Defines the path for of the Python installation folder on the remote server.



Once you've installed Python,  you can take a look at our Python demo with code examples.

→ Learn more at Python Integration DemoExample.


Using Python in the Solution

Image Removed

The

The Python Example illustrates how to use the Python and .NET languages for the Scripts.

This section presents a summary of that information, listing the modules in the solution where Python code can be used

at:

.

Image Added



Scripts Tasks and Classes

Displays Code Behind and Graphical Elements 

Shell Integration

Anchor#ScriptsTasksClasses

  • Scripts / Tasks: Event
#ScriptsTasksClassesScripts Tasks and Classes
  • Script-Tasks: event driven or periodical tasks, running in on the server computer. They can be written in Python, C# or VB.NET.
  • Scripts / Script Classes: library of methods and  functions functions that can be used in on both server and client machines, and by  Python, . They can be written in Python, C# or VB.Net Code.
Anchor#DisplaysCodeBehind
  • NET.
#DisplaysCodeBehind

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

    The Code Behind for the displays can be written in C#, VB.NET or JavaScript, not Python directly. But from the CodeBehind you can call tasks and methods, which can be written in Python.

    AnchorExternalShellIntegrationExternalShellIntegration

     

    Shell Integration

    • Shell Integration: executing allows you to execute Python code from external files.

    This integration allows you to execute Python code from external files. Just create a Script Task with the following code:

    Code Block
    languagepy
    titleSteel Shell Integration example
    # 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


    Tip
    titlePython Shell Version and Tests

    Any Python scripts you create in Scripts / Tasks can be edited and tested in Scripts / Code Editor. To test your script, click on [Monitor Icon] in the top toolbar. This will run your code and display messages in the Output Window, under the script editor.

    This integration will work if your Python version is 3.7 or newer, with Python.NET installed, and the executable is correctly mapped in Solution / Settings.



    Designer Python Code Editor

    Code Editor User Interface

    The code editor is accessed at the Designer Scripts → can be accessed through Scripts / Code Editor page.

    Testing the code

    When the editor is used to edit 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 will show in the standard Designer output.

    Accessing Tags and Modules

    properties

    Properties

    The access to Tags tags and other properties for other models is exactly the same as C# or VB.Net, NET; just use the '@' symbol to access directly the properties directly, as shown in the image: '@Tag.Tag1''@tag.Tag1


    .NET Interoperability

    Calling ScriptClass Methods

    At In the Script namespace, or in any code place in your solution where Expressions are allowed, call call methods defined on the script you can use the following syntax to call classes. 

    Code Block
    languagepy
    @Script.Class.TestClass.ExempleMethod(param1, param2)

    This activation is independent from of the language the class was created in.

    This means creating. Meaning C# and VB.NET can call Python classes, and Python code can call .NET classes.


    In this section:

    Page Tree
    root@parent