Introduction

Python Scripting in EcoStruxure Machine Expert

EcoStruxure Machine Expert includes a Python interpreter which can be used as a powerful tool to automate the development environment.

You can execute Python script files via the menu command Tools > Scripting > Execute Script File... in the main menu of the EcoStruxure Machine Expert Logic Builder.

The documentation for Python scripting in EcoStruxure Machine Expert consists of several parts:

The chapter Accessing the Python Interpreter in EcoStruxure Machine Expert describes how you can open the Python interpreter of EcoStruxure Machine Expert and how you can execute script files with it and how you can otherwise interact with it. The chapters Using the Logic Builder Shell, Using the Logic Builder Scripting Immediate View, and Keyboard Commands in the Logic Builder Shell and the Scripting Immediate View provide more details on individual parts.

The sections Schneider Electric Script Engine Examples and CODESYS Script Engine Examples provide various examples for how to automate EcoStruxure Machine Expert with Python scripts. These examples are given to provide a common thread that shows the capabilities of the EcoStruxure Machine Expert-specific API (Application Programming Interface) available to Python scripts.

The chapters Explore EcoStruxure Machine Expert Python API (with dir() and inspectapi), Best Practices, and EcoStruxure Machine Expert Scripting - Python API provide general hints on how to get started with Python scripting and how to explore the API provided.

The sections Schneider Electric - Script Engine Class Library and Script Engine Plugin API Reference provided in the Programming with EcoStruxure Machine Expert part of the EcoStruxure Machine Expert online help provide the reference of the EcoStruxure Machine Expert-specific API available to Python scripts. You can use these members in the same manner as described in the aforementioned examples.

Compatibility Between Python V2.x and Python V3.x

The Python interpreter delivered with EcoStruxure Machine Expert is an implementation of IronPython based on Python version 2.7.

NOTE: There are some major changes in the Python language definition between version 2.x and version 3.x. While the Python interpreter delivered with EcoStruxure Machine Expert is based on Python V2.x, it is possible that you can write code compatible with the version 3.x implementation. This involves, for example, using the from __future__ import print_function statement.

For more information, refer to the websites

Examples of new functions:

from __future__ import print_function
from __future__ import division
# New Python print syntax
print('Hello World!')
# Division
# Python 2 return an integer and rounds off
# Python 3 returns a float
print(17/3)

Coding Conventions

In order to harmonize and facilitate the work of different programmers on the same programming project, it makes sense to agree on a common programming style. EcoStruxure Machine Expert adheres to the Style Guide for Python Code. The scripts and examples delivered with EcoStruxure Machine Expert adhere to these conventions. For improved readability of code, it is a best practice that your own code adheres to the same conventions.

For further information, refer to the Style Guide for Python Code at http://www.python.org/dev/peps/pep-0008/.

Useful Links

For further information, refer to the following websites: