Post by i-campbell on build (F11) / generate code using a python script file
CODESYS Forge
talk
(Post)
hello, please enjoy. # i-campbell 2024 import subprocess from scriptengine import * # with a project already open # save if not yet saved # check pool objects if it is a library # generate code only for the active application if it is a project # beep thanks to https://devblogs.microsoft.com/scripting/powertip-use-powershell-to-send-beep-to-console/ if projects.primary: # check project is open if projects.primary.dirty: # save projects.primary.save() if projects.primary.path.lower().endswith('.library'): projects.primary.check_all_pool_objects() # check all pool objects for lib else: projects.primary.active_application.generate_code() # generate if not lib # note, there could be more applications than the active application, # this script does not generate those else: system.write_message(Severity.Error,'no project open') ps_output = subprocess.check_output(["powershell", "-Command", "[console]::beep(500,300)"]) # beep
Last updated: 2024-04-10
Documentation / Usage Help For Scripting Engine Libraries
CODESYS Forge
talk
(Thread)
Documentation / Usage Help For Scripting Engine Libraries
Last updated: 2023-08-21
Download Missing Libraries failed, Apache server HTTPS protocol
CODESYS Forge
talk
(Thread)
Download Missing Libraries failed, Apache server HTTPS protocol
Last updated: 2020-09-23
Download missing Libraries fails with 3.5patch 14 1+, sm3_basic
CODESYS Forge
talk
(Thread)
Download missing Libraries fails with 3.5patch 14 1+, sm3_basic
Last updated: 2023-12-06
The "Download missing libraries" feature stopped working
CODESYS Forge
talk
(Thread)
The "Download missing libraries" feature stopped working
Last updated: 2015-12-10
MQTT (Stefan Dreyer) - Errors after libraries were added
CODESYS Forge
talk
(Thread)
MQTT (Stefan Dreyer) - Errors after libraries were added
Last updated: 2021-08-16
Use CAA libraries in SoMachine Expert (Schneider Electric)
CODESYS Forge
talk
(Thread)
Use CAA libraries in SoMachine Expert (Schneider Electric)
Last updated: 2021-03-17
Problems with the libraries used in examples
CODESYS Forge
talk
(Thread)
Problems with the libraries used in examples
Last updated: 2020-01-30
Cannot send email using IIoT Libraries SL
CODESYS Forge
talk
(Thread)
Cannot send email using IIoT Libraries SL
Last updated: 2022-09-23
IIoT Libraries SL 1.6.0.0 Statusmeldung Per Mail senden
CODESYS Forge
talk
(Thread)
IIoT Libraries SL 1.6.0.0 Statusmeldung Per Mail senden
Last updated: 2022-05-03
Libraries that support meta file parsing
CODESYS Forge
talk
(Thread)
Libraries that support meta file parsing
Last updated: 2006-03-15
The state of the 3S CANopen libraries, alternatives
CODESYS Forge
talk
(Thread)
The state of the 3S CANopen libraries, alternatives
Last updated: 2012-09-12
Raspberry Pi: List of available drivers / libraries
CODESYS Forge
talk
(Thread)
Raspberry Pi: List of available drivers / libraries
Last updated: 2023-06-30
Wago Libraries codesys V2.3 in V3 nutzen
CODESYS Forge
talk
(Thread)
Wago Libraries codesys V2.3 in V3 nutzen
Last updated: 2017-03-23
Developing external libraries in 'C' using Visual studio
CODESYS Forge
talk
(Thread)
Developing external libraries in 'C' using Visual studio
Last updated: 2009-08-04
Verfügbarkeit von V2.3 Libraries und zukünftiger Support von Codesys V2.3
CODESYS Forge
talk
(Thread)
Verfügbarkeit von V2.3 Libraries und zukünftiger Support von Codesys V2.3
Last updated: 2018-06-04
Navigating CodeSys, inteface, adding hardware, libraries, addons....
CODESYS Forge
talk
(Thread)
Navigating CodeSys, inteface, adding hardware, libraries, addons....
Last updated: 2020-09-10
pdf documentation for libraries in e!cocpit
CODESYS Forge
talk
(Thread)
pdf documentation for libraries in e!cocpit
Last updated: 2020-06-25
IIoT Libraries SL - Azure IoT Hub Client build error
CODESYS Forge
talk
(Thread)
IIoT Libraries SL - Azure IoT Hub Client build error
Last updated: 2021-11-19
Problem with the license of libraries IIoT
CODESYS Forge
talk
(Thread)
Problem with the license of libraries IIoT
Last updated: 2024-04-04
IIot Libraries SL --> Web Socket Client SL Pong issue
CODESYS Forge
talk
(Thread)
IIot Libraries SL --> Web Socket Client SL Pong issue
Last updated: 2024-04-09
Raspberry Pi: List of available drivers / libraries
CODESYS Forge
talk
(Thread)
Raspberry Pi: List of available drivers / libraries
Last updated: 2024-06-11
Publish a JSON payload via MQTT Publish (using IIot Libraries)
CODESYS Forge
talk
(Thread)
Publish a JSON payload via MQTT Publish (using IIot Libraries)
Last updated: 2024-06-18
Modbus Master read/write over Ethernet UDP/TCP libraries
CODESYS Forge
talk
(Thread)
Modbus Master read/write over Ethernet UDP/TCP libraries
Last updated: 2024-07-10
Post by jst69 on Python script: Launch Codesys, Execute Script, Exit Codesys
CODESYS Forge
talk
(Post)
Dear all: Question about scripting: I am creating a .NET program that is supposed to Open codesys, open template project, export a bunch of pou, then exit codesys. Launch works, Open project works, Export works, But how do i tell codesys to close itself? I can tell windows to terminate codesys, but i would prefer to do it properly. from __future__ import print_function import sys import System proj = projects.primary # We're interested in POU nodes: POUGuid = Guid("6f9dac99-8de1-4efc-8465-68ac443b7d08") # We collect all POU nodes in that list. pous = [] # From the parent node on, we recursively add POU nodes: def CollectPous(node): if node.type == POUGuid: pous.append(node) else: for child in node.get_children(): CollectPous(child) # Now we collect all the leaf nodes. for node in proj.get_children(): CollectPous(node) # We print everything just to know what's going on. for i in pous: print("found: ", i.type, i.guid, i.get_name()) # And now we export the files. for candidate in pous: # We create a list of objects to export: # The object itsself objects = [candidate] # And sub-objects (POUs can have actions, properties, ...) objects.extend(candidate.get_children()) # And the parent folders. parent = candidate.parent while ((not parent.is_root) and parent.is_folder): objects.append(parent) parent = parent.parent # Create an unique file name: if len(sys.argv) == 1: filename = "parent\\%s.export" % (candidate.get_name()) else: filename = "%s\\%s.export" % (sys.argv[1],candidate.get_name()) # print some user information print("exporting ", len(objects), " objects to: ", filename) # and actually export the project. proj.export_xml(objects, filename) proj.close() print ("script finished.") System.exit(0) // Dont work .NET: public static void Export(string path,string proj) { if (checkSettings()) { var p = new System.Diagnostics.Process(); p.StartInfo.FileName = Properties.Settings.Default.CSVersion +"\\CODESYS\\Common\\CODESYS.exe"; p.StartInfo.Arguments = " --Profile=" + qoute(Properties.Settings.Default.CSProfile) + " --culture=en" + " --project=" + qoute(path + "\\" + proj) + " --runscript=" + Properties.Settings.Default.LastOpenProjectPath + "\\INPUT_DATA\\SCRIPT\\Export.py" + " --scriptargs:" + qoute(path) ; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = false; p.Start(); p.StandardOutput.ReadToEnd(); p.CloseMainWindow(); p.Close(); } }
Last updated: 2024-01-16
To search for an exact phrase, put it in quotes. Example: "getting started docs"
To exclude a word or phrase, put a dash in front of it. Example: docs -help
To search on specific fields, use these field names instead of a general text search. You can group with AND
or OR
.