Calling Scripts from Toolbar Icons
You can provide your own toolbar in the CODESYS user interface with up to 32 icons for calling script files. For this you need an ICO file where the icon is stored, and a PY file where the Python script to be called is stored.
In the installation directory or in the program files directory under CODESYS, you create a subdirectory named Script Commands
. In that directory, you create the config.json
configuration file. Specify the call information outline for each icon in the file. Here you can configure a maximum of 16 icons. You can also store the ICO and PY files in the same directory.
<CODESYS installation directory>\CODESYS\Script Commands
Users\<username>\AppData\Local\CODESYS\Script Commands
Default installation on Windows 10
C:\Program Files (x86)\CODESYS 3.5.14.0\CODESYS\Script Commands\ C:\Users\r.smith\AppData\Local\CODESYS\Script Commands
Tip
If you store a config.json
file with different call information at each of the storage locations, then you can configure up to 32 different icons.
Configuration file
Outline of the configuration file for 2 icons
[ { <icon call information> }, { <last icon call information> } ]
Outline of the call information <icon call information>
"Name": "<tooltip of the symbol button>", "Desc": "<description of the symbol button>", "Icon": "<icon file name>", "Path": "<path of the script file>"
| Required Displayed as symbol tooltip Example: |
| Optional Comment for the icon Example: Note: Not yet displayed in the user interface |
| Required File path: Example: Hint: If the file is in the same folder as the |
| Required Path of the Python script Example: Hint: If the file is in the same folder as the |
| Note: These parameters are not currently assessed. |
File config.json
[ { "Name": "Start", "Desc": "Starts processing", "Icon": "start.ico", "Path": "goon.py" }, { "Name": "Pause", "Desc": "Pause operation", "Icon": "pause.ico", "Path": "stop.py" }, { "Name": "Processing", "Desc": "Process again", "Icon": "VarStatSmall.ico", "Path": "process.py" } ]
The following files are located in the Script Commands
:
config.json goon.py stop.py process.py start.ico pause.ico VarStatSmall.ico
Creating script calls for a toolbar button
Create the
Script Commands
folder in one of the storage locations.C:\Users\<username>\AppData\Local\CODESYS
Create executable Python files there.
Example:
File
copy.py
print("The script COPY.PY is executed")
File
delete.py
print("The script DELETE.PY is executed")
Create the ICO files for the scripts.
Example:
Copy_before.ico
,Copy_below.ico
,CopyAll.ico
Create a configuration file
config.json
there.The folder
Users\<username>\AppData\Local\CODESYS\Script Commands
has the following content:Open
config.json
and add the outlined call information.[ { "Name": "Copy Before", "Desc": "Copy something", "Icon": "Copy_before.ico", "Path": "copy.py }, { "Name": "Copy Below", "Desc": "Copy something", "Icon": "Copy_below.ico", "Path": "copy.py" }, { "Name": "Copy All", "Desc": "Copy something", "Icon": "CopyAll.ico", "Path": "copy.py" }, { "Name": "Delete", "Desc": "Delete something", "Icon": "Delete.ico", "Path": "delete.py" } ]
Start CODESYS.
The script files, configuration file, and symbol files are read and provided in the Command Icons tab, in ScriptEngine Commands category.
dialog on theOpen the dialog toolbars.
and click on the tabSelect the empty toolbar there and click the Add Toolbar button.
A line editor opens at the empty toolbar.
Type in a name (example:
User defined toolbar
).The custom toolbar is displayed in the CODESYS window.
Add the recently imported commands and close the dialog.
Click one of the icons.
The following output is displayed in the message view.