In the realm of industrial automation, efficiency and precision are key pillars that underpin successful project development. Codesys, a widely used development environment for programming industrial controllers, offers a powerful tool that can significantly streamline project management processes – Codesys Scripting.
The Impact of Automation in Codesys Programming
Codesys Scripting empowers developers with the ability to automate various aspects of project creation and management. By harnessing the capabilities of scripting, users can expedite tasks such as creating projects, opening projects, adding devices, programs, and libraries, all with exceptional ease and accuracy.

Enhancing Efficiency through Scripting Libraries
One of the fundamental aspects of Codesys Scripting is its utilization of scripting libraries. These libraries contain predefined functions and routines that can be leveraged to automate specific actions within the Codesys environment. By incorporating these libraries into scripting tasks, developers can enhance efficiency, reduce manual errors, and ensure consistency across projects.
Below give table shows the objects which can be used in Codesys Scripting
Objects | Description |
System | Access to general CODESYS functionalities Examples:
|
projects | Access to the CODESYS project as an object tree that combines the three navigator views (devices, POUs, modules) in one project tree Also allows for the loading, creating, saving, and closing of projects For most objects in a project, there are special methods with detailed functionality, for example compiling, access to ST POUs, export, import, device configuration, etc. |
online | Access to online functionalities Examples:
|
librarymanager | Permits the management of library repositories and viewing, installation, and removal of libraries |
device_repository | Handling of device repositories; import and export of device descriptions |
modulerepository | Management of CODESYS Application Composer modules and CODESYS Application Composer repositories |
Streamlined Execution with Command Line Functionality
A notable feature of Codesys Scripting is its flexibility in execution. Users have the option to run scripts directly from the Codesys tool interface or through the command line. This versatility enables seamless integration of automation processes into existing workflows, allowing for streamlined
project development with minimal disruption.
From Command Menu Tools
From Command Line :
"C:\Program Files (x86)\CODESYS 3.5.17.0\CODESYS\Common\CODESYS.exe" --profile="CODESYS V3.5 SP17" --runscript="D:\Dokumente\Scripting\ArgvTestScript.py" --scriptargs:'username password 3.14 "path=\"C:\temp\\\""' --noUI
Harnessing Professional Precision with Codesys Scripting
For professionals in the field of industrial automation, precision is paramount. Codesys Scripting equips developers with the tools needed to achieve unparalleled accuracy in project management. Whether it's adding devices, programs, or libraries, each action can be executed with the utmost precision, ensuring project integrity and reliability.
Default Path for Script Engine is : C:\Program Files\CODESYS 3.5.xx.xx\CODESYS\ScriptLib\Stubs\scriptengine
this folder either you can use directly from original folder path or you can copy and paste it at project location of python
Creating Project
Opening Project & Adding Device
import sys
from scriptengine import * # Import necessary modules
proj=projects.open("C:\Users\Administrator\Documents\projects\TestProj.project")
for child in projects.primary.get_children():
if child.is_device:
child.add("test", type=110,id='0000 0002',version='4.2.0.0' )
candev=child.add("candev", type=15,id='181015',version='4.2.0.0' )
for child in projects.primary.get_children(recursive=True):
if child.is_device:
name=child.get_name()
if name=='candev':
for i in range(400):
devname="candev" + str(i)
child.add(devname , type=17,id='0000 0012',version='4.2.0.0' )
#child.add("candev2", type=17,id='0000 0012',version='4.2.0.0' )
if name=='test':
child.add('profinetctrl', type=80,id='0000 0002',version='4.4.0.0')
child.add('eip', type=120,id='0000 1016',version='4.5.1.0')
for child in projects.primary.get_children(recursive=True):
if child.is_device:
name=child.get_name()
if name=='eip':
child.add('eipmodule', type=102,id='0000 1016',version='4.1.0.0')
if name=='profinetctrl':
child.add('profinetdev', type=81,id='0x02CC_0x1017_IDD_1',version='SW=V4.4.0, HW=0')
for child in projects.primary.get_children(recursive=True):
if child.is_device:
name=child.get_name()
if name=='profinetdev':
child.insert('inputdev',index=1, type=81,id='0x02CC_0x1017_IDD_1',version='SW=V4.4.0, HW=0',module='IDM_1')
child.insert('outputdev',index=2, type=81,id='0x02CC_0x1017_IDD_1',version='SW=V4.4.0, HW=0',module='IDM_2')
child.insert('inoutdev',index=3, type=81,id='0x02CC_0x1017_IDD_1',version='SW=V4.4.0, HW=0',module='IDM_3')
proj.save()
Getting Details of Device
from __future__ import print_function
import sys
from scriptengine import * # Import necessary modules
def print_tree(treeobj, depth=0):
# if the current object is a device, we print the name and device identification.
if treeobj.is_device:
name = treeobj.get_name(True)
deviceid = treeobj.get_device_identification()
moduleid= treeobj.get_module_identification()
print("{0}- {1} {2}".format("--"*depth, name, deviceid,moduleid))
# we recursively call the print_tree function for the child objects.
for child in treeobj.get_children(True):
print_tree(child, depth+1)
# We iterate over all top level objects and call the print_tree function for them.
for obj in projects.primary.get_children():
print_tree(obj)
Add Library :
import sys
from scriptengine import * # Import necessary modules
proj = projects.primary
allobjects = Project.get_children(recursive=True)
for LibManager in allobjects:
if LibManager.is_libman:
for repo in librarymanager.repositories:
for lib in librarymanager.get_all_libraries(repo):
if lib.title == "Standard":
LibManager.add_placeholder("Standard", lib)
if lib.title == "CAA Device Diagnosis":
LibManager.add_placeholder("CAA Device Diagnosis", lib)
print("Libraries added")
Empowering Developers to Excel
Codesys Scripting opens doors to a realm of possibilities for developers seeking to excel in the world of industrial automation. By mastering the art of automation through scripting, professionals can elevate their expertise, optimize project workflows, and deliver solutions that meet the highest standards of quality and efficiency.

Embracing the Future of Automation
As the industrial landscape continues to evolve, the demand for streamlined processes and optimized workflows grows stronger. With Codesys Scripting, developers have a powerful ally that enables them to stay ahead of the curve, embrace automation technologies, and unlock new levels of productivity and innovation.
In conclusion, Codesys Scripting represents a game-changer in the realm of industrial automation, offering professionals a dynamic tool to automate project management tasks with precision and efficiency. By leveraging scripting libraries and command-line functionality, developers can elevate their workflows, optimize project development, and lead the way in shaping the future of industrial automation.
Remember, in the world of Codesys Scripting, precision is not just a goal – it's a professional standard that sets the stage for excellence.
Codesys Scripting Part 1
Codesys Scripting Part 2
Comentários