2.3 KiB
2.3 KiB
Configure Python Scripting in CODESYS IDE
This guide helps you enable and validate Python scripting in the CODESYS Development System.
1) Prerequisites
- CODESYS Development System installed
- A local Python installation (recommended: 64-bit)
- Permissions to install CODESYS packages/add-ons
Note: Python version compatibility can vary by CODESYS release. Check your CODESYS release notes if the scripting package requests a specific Python version.
2) Enable scripting support in CODESYS
- Start CODESYS IDE.
- Open the CODESYS package/add-on manager.
- Verify that scripting support is installed (usually shown as
Scripting,Script Engine, or similar CODESYS scripting component). - If missing, install the scripting package from CODESYS Store/Installer and restart CODESYS.
3) Verify Python environment in IDE
- Open the scripting window/console in CODESYS (menu name depends on version/profile).
- Confirm that the script console starts without errors.
- If CODESYS asks for a Python path/interpreter, set your local Python executable.
- Save settings and restart IDE once.
4) Run a first test script
Use this minimal script in the CODESYS script console/editor:
import sys
print("Python OK")
print(sys.version)
Expected result: no import/runtime errors and printed Python version output.
5) Connect script to an existing project
- Open your CODESYS project.
- From scripting console/editor, access the active project object (CODESYS scripting API).
- Start with read-only actions first:
- list devices
- list POUs
- print project metadata
- Then move to controlled write actions (for example, auto-creating folders/objects).
6) Common setup issues
- Scripting menu missing: scripting package not installed or wrong CODESYS profile.
- Interpreter errors: incompatible Python version or wrong executable path.
- Permission errors: run IDE with appropriate permissions for package/plugin install.
- API object errors: script written for another CODESYS version/API revision.
7) Recommended workflow
- Keep scripts in version control near your CODESYS project.
- Start with non-destructive scripts (reporting/checks) before auto-edit scripts.
- Add log output for every script action.
- Test scripts on a copy of the project before applying to production projects.