The 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.
provides an interface to several commands and events that can be executed while runningThe 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 Python scripts on the left-hand side.
editor lists the and that are available for triggering the execution of
To activate a command or event, select the respective item, and click the .
To deactivate a command or event, select the respective item, and click the .
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 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.
section provides the signature of the method that is called by the system after the event or command has been executed byThe 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.
button allows you to modify the name of theThe Python method when it is executed.
section lists the parameters that are available inside theThe 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.
editor allows you to program yourAccording to the selection you made in the Python script in the editor:
dialog box, you have the following options for creating yourFrom 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.
With the Python code is validated. If errors are detected, they are indicated in the view and the code will not be executed.
procedure, theIgnoring 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.