--- a +++ b/trunk/cforge/cforge/Package/CFORGE/Scripts/action.markdown.py @@ -0,0 +1,42 @@ +# Example Batch: +# set WD=%~d0%~p0 +# "C:\Program Files (x86)\3S CODESYS-V3.5.12.0\CODESYS\Common\CODESYS.exe" --profile="CODESYS V3.5 SP12" --runscript="%WD%\action.plcopenxml.export.py" --scriptargs="test.project" --noUI + +import sys, os +import os.path + +scriptpath = os.path.abspath(os.path.dirname(sys.argv[0])) +folder=sys.argv[1] +xsl=os.path.join(scriptpath, "plcopenxml.xsl") + +class ER(ExportReporter): + def error(self, object, message): + system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message)) + def warning(self, object, message): + system.write_message(Severity.Warning, "Warning exporting %s: %s" % (object, message)) + def nonexportable(self, object): + system.write_message(Severity.Information, "Object not exportable: %s" % object) + @property + def aborting(self): + return False; + +# Export all libraries and projects +reporter = ER() +for root, dirs, files in os.walk(folder): + for file in files: + if file.endswith(".library") or file.endswith(".project"): + print("Export project '%s'" % file) + print(reporter) + filename=str(os.path.join(root, file)) + tempname=str(os.path.join(root, file + ".xml")) + proj = projects.open(filename) + proj.export_xml(reporter, proj.get_children(False), tempname, recursive = True) + proj.close() + + # XSLT transform + print("Transform file with %s" % xsl) +else: + print("error: file not found '%s'" % file) + +system.exit() +