Showing results for 
Search instead for 
Did you mean: 

Access application node with python script

Access application node with python script

New Poster

How do I access the application node of a project with a python script.
Tested with sample script from 3S.

The intention to access the application from script is to test whether it would be possible to generate PLC projects from script, based on an EPLAN export as well as some additional parameter files or not. Generating PLC-projects via script is currently part of our workflow.



# encoding:utf-8
# We enable the new python 3 print syntax
from __future__ import print_function

# Prints out all devices in the currently open project.

print("--- Printing the devices of the project: ---")

# Define the printing function. This function starts with the
# so called "docstring" which is the recommended way to document
# functions in python.
def print_tree(treeobj, depth=0):
""" Print a device and all its children

treeobj -- the object to print
depth -- The current depth within the tree (default 0).

The argument 'depth' is used by recursive call and
should not be supplied by the user.

# if the current object is a device, we print the name and device identification.
if treeobj.is_device:
name = treeobj.get_name(False)
deviceid = treeobj.get_device_identification()
print("{0}- {1} {2}".format("--"*depth, name, deviceid))

# we recursively call the print_tree function for the child objects.
for child in treeobj.get_children(False):
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("--- Script finished. ---")







Community Moderator
Community Moderator

I didn't use that very interesting and powerful CoDeSys interface up to now. My expection is that this info must be available in the CoDeSys documentation.

Community Moderator
Community Moderator

We provide APIs for ctrlX PLC Engineering and ctrlX IO Engineering based on a REST API for automated creation of PLC programs and IO configurations. Maybe this is an alternate approach.

Community Moderator
Community Moderator

Here you find the CoDeSys Scripting Engine docu:;product=ScriptEngine;version=

Here an example to get applicaion node of active application.

# encoding:utf-8
from __future__ import print_function

proj = projects.primary             # get loaded project
app  = proj.active_application      # get active application
print("App Name=", app.get_name() ) # print application name

Community Moderator
Community Moderator