Introduction
The ctrlX PLC Engineering provides a powerful Python programming interface (Script Engine). This allows you to automate menu commands, as well as create and edit source code.
While the official CODESYS help page (CODESYS Scripting - Starting Scripts from Toolbars) explains how to integrate these scripts into the standard CODESYS environment, users of ctrlX WORKS face a challenge: The directory structure and paths of ctrlX PLC- Engineering are different.
ctrlX PLC Engineering searches for the script configuration in two locations:
ctrlX PLC Engineering AppData directory (version-independent)
ctrlX PLC Engineering installation directory (version-specific)
Prerequisites & Locating the Path
ctrlX PLC Engineering AppData directory
If multiple versions of ctrlX PLC Engineering are installed, they all load the script configuration. Replace <user> by your username.
C:\Users\<user>\AppData\Local\ctrlX PLC Engineering\Script Commands
ctrlX PLC Engineering installation directory
Only the ctrlX PLC Engineering version into whose directory structure the script configuration has been copied reads it in.
The default installation directory is usually: C:\Program Files\ctrlX WORKS\ctrlX PLC Engineering\<Version-Number>
Tip for easily finding the path:
Right-click the desktop shortcut for ctrlX PLC Engineering and open its Properties.
Look at the path in the "Start in" field (e.g., "C:\Program Files\ctrlX WORKS\ctrlX PLC Engineering\3.6.3\Studio\Common").
Ignore the last two directories (\Studio\Common). The relevant base path for the next steps in this example is:
"C:\Program Files\ctrlX WORKS\ctrlX PLC Engineering\3.6.3"
Install example files
Step-by-Step Guide
Step 1: Create one of the directories mentioned above.
Note: Creating this folder and copying files into it later might require administrator privileges.
Step 2: Extract and Copy the Sample Files
Extract the ZIP archive (Commands.zip) and copy all the included files directly into the newly created "Scripts Commands" directory.
The ZIP archive contain the following files:
icon-a.ico (Icon for toolbar button of Script A)
icon-b.ico (Icon for toolbar button of Script B)
script-a.py (Your Python script A)
script-b.py (Your Python script B)
config.json (The configuration file for the menu integration)
Configuration File Structure (config.json)
This file controls how ctrlX PLC Engineering reads the scripts and displays them in the user interface. The table below shows the structure of the file and explains each parameter:
Copy
[
{
"Name": "hello world A",
"Desc": "description python test",
"Icon": "icon-a.ico",
"Path": "script-a.py"
},
{
"Name": "hello world B",
"Desc": "description python test",
"Icon": "icon-b.ico",
"Path": "script-b.py"
}
]"Name" is display as tooltip
"Desc" description of the script not yet displayed
"Icon" name of the icon file
"Path" name of the script file
Verifying the Integration
Once the files are placed in the folder, they will be loaded automatically the next time you start ctrlX PLC Engineering. Follow these steps to verify that everything was imported correctly:
Start ctrlX PLC Engineering.
In the menu, navigate to Tools > Customize > Command Icons.
Select the category ScriptEngine Commands from the list.
Your configured scripts (e.g., hello world A and hello world B) should now be listed here with their assigned icons.
Now you can add the scripts to a new or an existing toolbar.