FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We are updating our platform to a new
system.
Read more: Important
information on the platform change.
03-05-2021 03:47 PM - edited 03-05-2021 04:22 PM
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.
Script:
# 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
Arguments:
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_tree(obj)
print("--- Script finished. ---")
Project:
Output:
Solved! Go to Solution.
05-19-2021 02:02 PM
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.
05-21-2021 11:35 AM
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.
05-26-2021 06:17 PM
Here you find the CoDeSys Scripting Engine docu: https://help.codesys.com/webapp/ScriptProject;product=ScriptEngine;version=3.5.16.0
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
05-27-2021 11:11 AM
Online-Docu "Using scripts to automate commands ..." :
https://help.codesys.com/webapp/_cds_struct_using_scripts;product=codesys;version=3.5.16.0