Version: 1.5.5
Important
Disclaimer: This is a third-party tool. It is NOT an official product of CODESYS Group and is not affiliated with, sponsored by, or endorsed by CODESYS Group. This tool is provided "as is" and is not a replacement for official CODESYS products.
This repository contains a set of Python scripts for CODESYS that facilitate a modern Git-based workflow for PLC development.
- Goal: Edit code using modern external tools (VS Code, Cursor, Copilot) and sync changes back to CODESYS.
- Method: Exports logic (POUs, GVLs, DUTs) to clean Structured Text (.st) files.
- Benefit: You can refactor code, use AI assistants, or mass-edit variables externally. The
Project_import.pyscript then seamlessly updates your open CODESYS project.
- Reversible Sync: Round-trip editing for Structured Text files.
- Binary Backup (Git LFS): Optionally keeps a synchronized copy of your
.projectfile for version control. - Native XML Export: Optionally exports visualizations, alarms, and text lists to XML for diffing.
- Safety: Built-in checks (PC Name, Project Name) to prevent overwriting the wrong project.
- Bi-directional Deletion: Keep your file system and CODESYS project in sync by removing orphaned files.
- Background Service: A daemon that provides global hotkeys (
Alt+Q) for quick actions without switching windows.
- Copy Files: Copy all
.pyfiles to the CODESYS scripts directory:C:\Users\<YourUsername>\AppData\Local\CODESYS\ScriptDir\(Note: You may need to create theScriptDirfolder manually if it doesn't exist).
Automate the installation, folder creation, and Git configuration with one command:
irm https://raw.githubusercontent.com/ArthurkaX/cds-text-sync/main/irm/setup.ps1 | iexTip
For a detailed explanation of what the script does, check the Quick Setup Guide.
-
Access in CODESYS:
- The scripts will be available in Tools > Scripting > Scripts > P.
-
Add to Toolbar (Recommended):
- Go to Tools > Customize > Toolbars.
- Add commands from ScriptEngine Commands > P.
When upgrading to a new version of cds-text-sync:
- Replace Script Files: Copy the new
.pyfiles to your CODESYS scripts directory, overwriting the old versions. - Clean Export: Run
Project_export.pyto re-export all files with the updated format. - Commit Changes: Review and commit the changes in Git.
Tip: A clean export after upgrading ensures all files use the latest export format and prevents inconsistencies.
Run this first. It links your current CODESYS project to a specific folder on your disk.
- Offers two options:
- Browse: Select a folder using the file browser (traditional method).
- Manual Input: Enter a path manually, supporting both absolute and relative paths.
- Relative Path Support:
- Use
./to sync to the same directory as your project file. - Use
./src/or./foldername/to sync to a subfolder relative to your project. - Perfect for team collaboration: Relative paths work on any machine without reconfiguration, as they're resolved relative to the project file location.
- The folder will be created automatically if it doesn't exist.
- Use
- Saves the path (
cds-sync-folder) and current machine name (cds-sync-pc) to Project Information > Properties. - This binding ensures you don't accidentally sync to the wrong folder.
Examples:
- Absolute path:
C:\MyProjects\MyPLC\sync\ - Relative path (project directory):
./ - Relative path (subfolder):
./sync/or./git-repo/src/
Configure how the sync works. Runs an interactive menu to toggle options. Settings are saved in the project file.
- [ ] Export Native XML:
- If ENABLED: visual objects (Visualizations, Alarms, ImagePools) are exported to
/xmlfolder in PLCopenXML format. - Useful for tracking changes in non-textual objects.
- If ENABLED: visual objects (Visualizations, Alarms, ImagePools) are exported to
- [ ] Backup .project binary:
- If ENABLED: the script creates a copy of your
.projectfile in the/projectfolder. - Essential for Git LFS workflows. Ensures your binary state matches your code state.
- If ENABLED: the script creates a copy of your
- Set Backup Name:
- Allows you to specify a fixed filename for the binary backup (e.g.,
Project). - Why use it? If you often rename your
.projectfiles or work in a team where project names vary, setting a fixed name ensures the backup always overwrites the same file. This keeps your/projectfolder clean and prevents Git history from being cluttered with "new" files that are just renamed versions of the old ones.
- Allows you to specify a fixed filename for the binary backup (e.g.,
- [ ] Save Project after Import:
- If ENABLED: automatically saves the project after a successful import.
- [ ] Silent Mode:
- If ENABLED: suppresses blocking popup messages and uses non-blocking system tray notifications (toasts).
- Recommended for "Developer Workflow" to stay in flow.
Exports the current project state to the sync folder.
- Source Code: Exports all POUs, GVLs, DUTs to
/srcas.stfiles. - Libraries: Saves
_libraries.csvfor dependency tracking. - Binary Backup: If enabled, saves the project and copies it to
/project. - Cleanup: Detects files on disk that no longer exist in CODESYS and offers to delete them.
Updates the CODESYS project from the files on disk.
- Smart Update: Updates existing objects, creates new ones, and builds folder hierarchies.
- Deletions: If a file was deleted from disk, offers to delete the object from CODESYS.
- Binary Sync: If "Backup .project binary" is enabled, it automatically saves the project after import and updates the binary backup, ensuring Git consistency.
The ultimate productivity booster. This script runs in the background and empowers you to control CODESYS from anywhere.
- Global Hotkey (Alt + Q): Open the Quick Action Dashboard from any application or virtual desktop.
- Silent Operations: Perform Exports, Imports, and Builds without interrupting your flow with popup dialogs.
- Smart Focus: The dashboard intelligently steals focus when activated and restores it to your previous window (e.g., VS Code) when done.
- Build & Log: Trigger a project build and get a clean, table-formatted
build.logdirectly in your project folder.
Usage:
- Run
Project_Daemon.pyonce inside CODESYS to start it. - Press
Alt + Qto toggle the menu. - Press
Din the menu or run the script again to stop it.
- Integration: The specific error format allows external editors (like VS Code tasks) to parse the log and highlight errors in your original source files.
Identify differences between IDE and Disk. Compares the objects in your CODESYS project with the exported files on disk.
- Detection: Finds modified objects, new objects in IDE, and objects deleted from IDE.
- Output: Generates a detailed report in the Script Output window and saves it to
compare.log. - Clean Run: The
compare.logfile is recreated every time you run the script, ensuring you only see the latest results. - Daemon Integration: Can be triggered directly from the Quick Action Dashboard ('C' key).
For projects involving multiple engineers, we recommend a structured Git-based workflow.
- Detailed Team Workflow Guide: Learn how HMI/Hardware engineers and software developers can collaborate effectively using branches and Pull Requests.
The tool organizes your repository into a clean structure:
/
βββ src/ # The Logic Source. All .st files (POUs, GVLs, DUTs).
βββ project/ # (Optional) The State Backup. Copy of .project for Git LFS.
βββ xml/ # (Optional) Native XML exports of Visualizations/Alarms.
βββ config/ # Environment config (Libraries, TaskConfig).
βββ sync_debug.log # Diagnostic log for the last sync operation.
βββ build.log # Build output log.
βββ compare.log # Comparison results log.
βββ _metadata.csv # Split object metadata (Do not delete!)
βββ _config.json # Project configuration mirror.
βββ _libraries.csv # Library version tracking.
- Configure: Run
Project_parameters.pyand enable "Backup .project binary". - Export: Run
Project_export.py.- Code goes to
/src. - Binary goes to
/project.
- Code goes to
- Commit:
git add .git commit -m "Update logic"- Git tracks the text in
src/. - Git LFS tracks the binary in
project/.
- Edit: make changes in VS Code or CODESYS.
- Sync: Run
Project_import.pyorProject_export.pydepending on where you edited.- The binary backup is automatically updated on every sync.
Since .project is a binary file, standard Git is not efficient at tracking its changes.
- Prevents Bloat: Normal Git stores the entire file for every commit. If your project is 10MB, 100 commits would make your repo 1GB. LFS prevents this.
- Performance: You only download the binary version you are currently working on, keeping
git cloneandgit fetchfast. - Code-Binary Sync: It allows you to keep the "full state" of the project (Visualizations, HW config) exactly matched with the "logic state" in
src/.
Relative Path Support for Team Collaboration:
- Portable Project Configuration:
Project_directory.pynow supports relative paths (e.g.,./,./src/) in addition to absolute paths. - Manual Path Input: Added a new "Manual Input" option in the directory setup dialog, allowing users to type paths directly.
- Automatic Directory Creation: If a specified directory doesn't exist, it will be created automatically.
- Team-Friendly: Relative paths are resolved relative to the project file location, making projects portable across different machines and users without reconfiguration.
- Examples:
./- Sync to project directory./sync/- Sync to a subfolderC:\MySync\- Traditional absolute path still supported
Comparison Logging & Rerouting:
- Dedicated Comparison Log:
Project_compare.pynow reroutes its output tocompare.login the sync directory. - Recreative Logging: The log file is truncated and recreated on every run, providing a fresh report for each comparison.
- Tee Output: Comparison results are still mirrored to the CODESYS Script Output window for immediate feedback.
Line Ending & Git Consistency Fix:
- Cross-Platform Consistency: Fixed an issue where different line endings (CRLF vs LF) on different machines caused Git to show identical files as modified.
- Deterministic Export: The export script now explicitly uses LF (
\n) for all.stfiles regardless of the host OS by usingnewline=''in file operations. - Automated Git Configuration: Updated the
.gitattributestemplate to automatically disable text conversion for.stfiles (*.st -text), ensuring they remain as LF in the repository and are treated consistently by Git on all platforms.
Improved Property Sync & Bug Fixes:
- Enhanced Property Support: Properties with combined GET/SET accessors are now correctly handled. The export script now accurately combines both the
VARdeclaration and implementation code for each accessor into a single.stfile. - Bi-directional Accessor Sync: The import script now correctly parses combined accessor content and updates both the declaration and implementation in CODESYS.
- Object Restoration: Fixed an issue where objects deleted from CODESYS but remaining on disk would not be recreated. They are now automatically detected and restored during import.
- Bug Fix (#4): Resolved an issue where properties created manually in external editors (or by AI) were incorrectly identified or failed to import.
Performance & Optimization Update:
- CRC32 Hashing: Switched from SHA256 to CRC32 for file tracking, achieving 10-20x faster hashing performance and significantly reducing metadata size.
The "Power User" Update:
- Project_Daemon.py: New background service with Global Hotkey (
Alt + Q). - Quick Action Dashboard: Instant access to Export, Import, Build, and Backup commands.
- Enhanced Build Log:
Project_Build.pynow generates a clean, readable table format inbuild.logwith accurate line numbers for external editors. - Focus Management: Daemon correctly handles focus switching between Virtual Desktops and restores context after execution.
UI & Experience Overhaul:
- Configuration Dialog: Replaced the text-based menu with a modern Windows Forms dialog for easier configuration.
- Silent Mode: Added a "Silent Mode" option that uses non-blocking system tray notifications (toasts) instead of blocking popups.
- Safety: Added checks to prevent sync on wrong machine (PC Name check).
Binary Backup & Configuration Overhaul:
- Project_parameters.py: New interactive menu to toggle features.
- Binary Backup: Added optional
.projectfile backup loop. The binary is now updated on both Export and Import events. - Logging: Moved
sync_debug.logto the project sync folder (or Temp) to keepScriptDirclean. - Import Logic: Removed interactive menu from Import script; now uses project settings.
Safety & Validation:
- PC Check: Validates
cds-sync-pcto prevent syncing on the wrong machine. - Properties: All settings are now stored in Project Properties (
cds-sync-*).
- Full support for nested folders.
- Detection of deletions (Orphan cleanup).
- Library version tracking (
_libraries.csv).
MIT License.


