[r18]: / trunk / cforge / cforge / Package / CFORGE / Scripts / plcopenxml_export.py  Maximize  Restore  History

Download this file

42 lines (29 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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%\plcopenxml_export.py" --scriptargs="test.project" --noUI

# this is a script to control the PLCopen XML export of a given project/library file
# it generates a plcopen xml file with the same name as the given file + ".plcopen.xml"
#


import sys
import os.path


def export(file):
	if os.path.isfile(file):
		reporter = ER()
		proj = projects.open(file)
		
		print("exporting plcopen xml: " + file )
		proj.export_xml(reporter, proj.get_children(False), file + ".plcopen.xml", True, True, True)
		
	else:
		print("error: file not found '%s'" % file)



if __name__ == "__main__":
	file=sys.argv[1]
	export(file)

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;