The provides an interface to several commands and events that can be executed while running EcoStruxure Machine Expert. The execution of the command or detection of the event can trigger the execution of a specific Python script. You can program your own Python script or you can use one of the Python templates that is delivered with EcoStruxure Machine Expert.
The AutomaticProjectArchiveCreation.py template, for example, provides a Python script for creating a project archive. If different users are working on the same project, this helps to ensure that a project archive is created whenever the project has been changed by whichever person. Thus, each user is supplied with the latest state of the project if the latest project archive is used.
For further information, refer to the following Script Engine User Guides provided in the Software - Programming part of the EcoStruxure Machine Expert online help:
CODESYS Script Engine - User Guide
EcoStruxure Machine Expert Script Engine - User Guide
To create a object, proceed as follows:
|
Step |
Action |
Comment |
|---|---|---|
|
1 |
Right-click the Global node of the tree and execute the command . |
Result: The dialog box opens. |
|
2 |
Select the suitable option for creating a Python script. |
|
|
3 |
Click the button. |
Results:
|
The editor lists the and that are available for triggering the execution of Python scripts on the left-hand side.
To activate a command or event, select the respective item, and click the button
.
To deactivate a command or event, select the respective item, and click the button
.
These status settings are saved to the project. For example, if you open a project that was previously saved with a hook enabled, this hook remains active and is triggered as soon as the event / command becomes valid.
On the right-hand side, further information is presented for the selected command or event:
The section provides the signature of the method that is called by the system after the event or command has been executed by EcoStruxure Machine Expert. Click the button to insert the code into your Python code in the editor and extend this method by the Python commands you want to execute.
The button allows you to modify the name of the Python function in a separate dialog box. After you have saved a different name, make sure that you use the exact string of the modified name in your Python code.
The section lists the parameters that are available inside the Python method when it is executed.
The editor allows you to program your Python script directly in Logic Builder. The editor supports all Python programming features, even though the Autocomplete (IntelliSense) function does not provide all available Python keywords for selection.
According to the selection you made in the dialog box, you have the following options for creating your Python script in the editor:
From scratch, starting with an empty editor, by entering your code and using the code snippets you copy from the section of the editor.
From template, by using the script provided by the selected template as a basis and extending it by your specific Python code.
By importing the Python script you programmed in another tool.
button to synchronize the script and to apply the modifications. If you exit the editor without synchronization, modifications are saved and are thus still available in the editor but they are not applied. The previous script without modification is still executed instead. If you load another project or create a new project, a different script - or no script at all - will be available.
With the procedure, the Python code is validated. If errors are detected, they are indicated in the view and the code will not be executed.
Ignoring Multiple Events During Login/Logout
For example, ignore the multiple execution of the AfterDeviceLogin event with the help of a flag in the script:
def after_device_login():
if session_store.get("loginHandled", False) == False:
print("after_device_login")
session_store.set("loginHandled", True)
pass
def after_device_logout():
print("after_device_logout")
session_store.set("loginHandled", False)
pass
The texts you program in your Python code with the print command are displayed in the area of the view.