I wanted to create a script which could import an XML file.
I first exported a GVL and wanted to import it, but I noticed it was placed in the POU pool.
With this example it places it "under" the application of the Device.
Create the .xml file, open a project with a device (PLC) and application and run the script.
\# script example importXML.py
\# current projectproj=projects.primary
\# create the import reporterclassReporter(ImportReporter):deferror(self,message):system.write_message(Severity.Error,message)defwarning(self,message):system.write_message(Severity.Warning,message)defresolve_conflict(self,obj):returnConflictResolve.Copydefadded(self,obj):print("added: ",obj)defreplaced(self,obj):print("replaced: ",obj)defskipped(self,obj):print("skipped: ",obj)@propertydefaborting(self):returnFalse
\# create the importer instance.reporter=Reporter()
\# import xmlobj=proj.find("Application",True)i=len(obj)print("number of item Application: {0}".format(i))ifi>0:obj[0].import_xml(reporter,r"C:\_d\Python\importXML\myXML.xml")print("add item")
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I wrote a script, which imports a XML to CoDeSys. Than I saw here in the forum, that you had created a script for importing XML. You defined in your script a class "Reporter". Could you please explain the function of this class. Is it important to have this class in the script?
Thanks a lot.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can see that the import function uses the reporter class, therefore I added it.
The example is based on an example in the help and some addional help from 3S-Software.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-10-19
Originally created by: M.Schaber
Hi,
The import and export process gives notifications about errors, warnings and progress. The purpose of the reporter is to process those notifications during the export or import process.
For native export, passing the reporters is optional. For PLCOpenXML, we're working on making them optional.
HTH,
Markus
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had exported some properties of a function block as XML-file using the menu function "Export PLCopen XML" and then wanted to import that with the function import_xml(). That worked fine, but all commentaries of the properties were not imported.
Example:
// P-0-0011 -READ- Last valid position command value <-- This was not imported !!!
PROPERTY P_0_0011 : DINT <-- This was imported !!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-03-20
Originally created by: M.Schaber
Hi, Lohr_DCIA-EHE1,
Lohr_DCIA-EHE1 hat geschrieben:
I had exported some properties of a function block as XML-file using the menu function "Export PLCopen XML" and then wanted to import that with the function import_xml(). That worked fine, but all commentaries of the properties were not imported.
Example:
// P-0-0011 -READ- Last valid position command value <-- This was not imported !!!
PROPERTY P_0_0011 : DINT <-- This was imported !!!
Can check whether the comments are correctly imported when you do the import via the menu function?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The import of the commentaries of the properties via the menu function does not work either.
All commentaries above FUNCTION_BLOCK MX_DirectVarAxis are lost, too !!
// {attribute 'signature_flag' := '12345'} <-- lost
//{attribute 'hide'}//hide POU <-- lost
{attribute 'signature_flag' := '1275068416'} <-- lost
FUNCTION_BLOCK MX_DirectVarAxis <-- from here on everything is copied.
VAR
//{attribute 'hide'}//hide POU
{attribute 'noinit'}
usCmdAchse : UINT; // Achse fuer den Parameter-Zugriff
END_VAR
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-03-20
Originally created by: M.Schaber
Lohr_DCIA-EHE1 hat geschrieben:
The import of the commentaries of the properties via the menu function does not work either.
All commentaries above FUNCTION_BLOCK MX_DirectVarAxis are lost, too !!
// {attribute 'signature_flag' := '12345'} <-- lost
//{attribute 'hide'}//hide POU <-- lost
{attribute 'signature_flag' := '1275068416'} <-- lost
FUNCTION_BLOCK MX_DirectVarAxis <-- from here on everything is copied.
VAR
//{attribute 'hide'}//hide POU
{attribute 'noinit'}
usCmdAchse : UINT; // Achse fuer den Parameter-Zugriff
END_VAR
Then it's a general PLCOpenXML problem, and not specific to scripting. So I'm afraid I'm not in charge of it.
I think the best is that you file a bug report via our support department. Especially mention that the {attribute}s are lost, as that information is more important than "noarmal" comments.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I wanted to create a script which could import an XML file.
I first exported a GVL and wanted to import it, but I noticed it was placed in the POU pool.
With this example it places it "under" the application of the Device.
Create the .xml file, open a project with a device (PLC) and application and run the script.
more posts ...
Hi TimvH,
I wrote a script, which imports a XML to CoDeSys. Than I saw here in the forum, that you had created a script for importing XML. You defined in your script a class "Reporter". Could you please explain the function of this class. Is it important to have this class in the script?
Thanks a lot.
You can see that the import function uses the reporter class, therefore I added it.
The example is based on an example in the help and some addional help from 3S-Software.
Originally created by: M.Schaber
Hi,
The import and export process gives notifications about errors, warnings and progress. The purpose of the reporter is to process those notifications during the export or import process.
For native export, passing the reporters is optional. For PLCOpenXML, we're working on making them optional.
HTH,
Markus
I had exported some properties of a function block as XML-file using the menu function "Export PLCopen XML" and then wanted to import that with the function import_xml(). That worked fine, but all commentaries of the properties were not imported.
Example:
// P-0-0011 -READ- Last valid position command value <-- This was not imported !!!
PROPERTY P_0_0011 : DINT <-- This was imported !!!
Originally created by: M.Schaber
Hi, Lohr_DCIA-EHE1,
Can check whether the comments are correctly imported when you do the import via the menu function?
The import of the commentaries of the properties via the menu function does not work either.
All commentaries above FUNCTION_BLOCK MX_DirectVarAxis are lost, too !!
// {attribute 'signature_flag' := '12345'} <-- lost
//{attribute 'hide'}//hide POU <-- lost
{attribute 'signature_flag' := '1275068416'} <-- lost
FUNCTION_BLOCK MX_DirectVarAxis <-- from here on everything is copied.
VAR
//{attribute 'hide'}//hide POU
{attribute 'noinit'}
usCmdAchse : UINT; // Achse fuer den Parameter-Zugriff
END_VAR
Originally created by: M.Schaber
Then it's a general PLCOpenXML problem, and not specific to scripting. So I'm afraid I'm not in charge of it.
I think the best is that you file a bug report via our support department. Especially mention that the {attribute}s are lost, as that information is more important than "noarmal" comments.
Great info from 2011... thanks!