<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/</id><updated>2020-02-27T14:53:21.358000Z</updated><subtitle>Recent posts to Scripting - examples and receipes</subtitle><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#5db3" rel="alternate"/><published>2020-02-27T14:53:21.358000Z</published><updated>2020-02-27T14:53:21.358000Z</updated><author><name>jvm68</name><uri>https://forge.codesys.com/u/jvm68/</uri></author><id>https://forge.codesys.comd21347318278d651ef284371cd5a93cc09db8ed5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;is it possible just to use just one script instead od two , if always execute codesys from the PC.?&lt;br/&gt;
other question, is it possible to introduce the variables from the scrip, with informtion from other program?&lt;/p&gt;
&lt;p&gt;Thanks for your help.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#509c" rel="alternate"/><published>2020-02-27T14:53:20.769000Z</published><updated>2020-02-27T14:53:20.769000Z</updated><author><name>etamgul</name><uri>https://forge.codesys.com/u/etamgul/</uri></author><id>https://forge.codesys.comf5093aad1b62f539704cb1efa9b41a7779433fd8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;In my case onlineapp.application_state does not work properly when script is executed with --noUI switch.&lt;/p&gt;
&lt;p&gt;I wanted to test that in case of an exception (thrown because the runtime got a wrong UDP packet) the application is stopped,&lt;br/&gt;
thus I needed a python script to send the proper UDP packets when I realized that using the --noUI switch influences the result of the &lt;br/&gt;
execution and this was because the onlineapp.application always returned me 'run'.&lt;/p&gt;
&lt;p&gt;Could somebody confirm this?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#7f75" rel="alternate"/><published>2020-02-27T14:53:19.073000Z</published><updated>2020-02-27T14:53:19.073000Z</updated><author><name>mkeller</name><uri>https://forge.codesys.com/u/mkeller/</uri></author><id>https://forge.codesys.com4da07d5fa73ded5d1685be891530aa9862cf71b7</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;etamgul hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Is there a way to read the device log using the scripting interface?&lt;br/&gt;
E.g. when an exception happens and I retreive that the application has been stopped but would like to know the reason.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Right now, this is not yet possible, but this improvement is already listed in our Jira tracker &lt;a class="" href="http://jira.3s-software.com/browse/CDS-31928" rel="nofollow"&gt;CDS-31928&lt;/a&gt;, so it will be implemented eventually.&lt;/p&gt;
&lt;p&gt;BR&lt;br/&gt;
Martin&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#aa3b" rel="alternate"/><published>2020-02-27T14:53:18.456000Z</published><updated>2020-02-27T14:53:18.456000Z</updated><author><name>etamgul</name><uri>https://forge.codesys.com/u/etamgul/</uri></author><id>https://forge.codesys.comacb3ee5aac3da753e39f50d104ca1ad4d9fc8d4a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Is there a way to read the device log using the scripting interface?&lt;br/&gt;
E.g. when an exception happens and I retreive that the application has been stopped but would like to know the reason.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#de2e" rel="alternate"/><published>2020-02-27T14:53:16.759000Z</published><updated>2020-02-27T14:53:16.759000Z</updated><author><name>etamgul</name><uri>https://forge.codesys.com/u/etamgul/</uri></author><id>https://forge.codesys.com4c83f8c9ee292c911acd3e1cf46d64320bb78afc</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Mystic hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Is there any documents or manuals including these 'namespace' in CoDeSys?&lt;br/&gt;
I can't find it on my PC and internet. &lt;br/&gt;
Thanks a lot.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Yes it is documented in the online manual and also 3S CODESYS\CODESYS\Online Help\ScriptEngine.chm&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#cdf2" rel="alternate"/><published>2020-02-27T14:53:16.097000Z</published><updated>2020-02-27T14:53:16.097000Z</updated><author><name>Mystic</name><uri>https://forge.codesys.com/u/mystic/</uri></author><id>https://forge.codesys.com041fca3ba7083f97be3a857a30fa248933e260fd</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Zitat:&lt;/strong&gt;&lt;br/&gt;
"projects" is an object imported into the namespace for scripts running in CoDeSys, so it is only available if your script is being started in CoDeSys directly (either via the "Execute Script" menu command or button, or via the "--runscript" command line parameter.)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Is there any documents or manuals including these 'namespace' in CoDeSys?&lt;/p&gt;
&lt;p&gt;I can't find it on my PC and internet. &lt;/p&gt;
&lt;p&gt;Thanks a lot.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#c3e0" rel="alternate"/><published>2020-02-27T14:53:15.395000Z</published><updated>2020-02-27T14:53:15.395000Z</updated><author><name>etamgul</name><uri>https://forge.codesys.com/u/etamgul/</uri></author><id>https://forge.codesys.com232cdf740f3eebd473bf2dc5ca24fe2fecd5650e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I'm currently trying to make this script execution work (using the "ScriptEnginePluginAPIReference" and "CoDeSys" help)&lt;br/&gt;
with the examples given in help files, and seems to work but ran into some unexpected trouble.&lt;/p&gt;
&lt;p&gt;I wanted to store my project settings and code in PLCopenXML so I made a project, exported everything,&lt;br/&gt;
using the example script I imported the XML to an empty project (so far it worked) but when I tried to upload&lt;br/&gt;
and login I got an error: gateway is not configured.&lt;/p&gt;
&lt;p&gt;So I wrote a simple script: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;    &lt;span class="nv"&gt;def&lt;/span&gt; &lt;span class="nv"&gt;_setGateway&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;self&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;:
        &lt;span class="nv"&gt;objects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;self&lt;/span&gt;.&lt;span class="nv"&gt;proj&lt;/span&gt;.&lt;span class="nv"&gt;get_children&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;recursive&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;True&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;        
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;dev&lt;/span&gt; &lt;span class="nv"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;objects&lt;/span&gt;:
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;dev&lt;/span&gt;.&lt;span class="nv"&gt;get_name&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Device&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;:
                &lt;span class="nv"&gt;proj_device&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;dev&lt;/span&gt;
        
        &lt;span class="nv"&gt;gateway_guid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;proj_device&lt;/span&gt;.&lt;span class="nv"&gt;get_gateway&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;
        #&lt;span class="nv"&gt;gateway_guid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3261a15d-434d-4868-9e1f-1bfa38e92408&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;
        &lt;span class="nv"&gt;gateway_dev_addr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;some-hardcoded-value&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;
        &lt;span class="nv"&gt;proj_device&lt;/span&gt;.&lt;span class="nv"&gt;set_gateway_and_address&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;gateway_guid&lt;/span&gt;, &lt;span class="nv"&gt;gateway_dev_addr&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The script had been checked and its working &lt;em&gt;under a preset project file&lt;/em&gt;.&lt;br/&gt;
Problems:&lt;br/&gt;
1st) when I execute it on a newly (script) created empty project file (after XML import)&lt;br/&gt;
the gateway GUID is NULL (00000-000-0000-0000), if I set the gateway (manually) in that project&lt;br/&gt;
and save the project and than re-execute this script I get a valid GUID.&lt;/p&gt;
&lt;p&gt;2nd) Even if I hardcode the correct GUID and the correct address (I can see the script setting itt correctly,&lt;br/&gt;
because I set the addr to a wrong value before) the login command throws me an error that the device&lt;br/&gt;
could not be reached because of connection problems. Again if I set it manually and save the project,&lt;br/&gt;
login works perfectly.&lt;/p&gt;
&lt;p&gt;Another major problem that I came across with is the following (either my python knowledge is limited here&lt;br/&gt;
or just a simple explanation can solve this), using a python script through command line will only grant&lt;br/&gt;
that and only that python script the visibility to codesys supplemented interfaces, once another script is &lt;br/&gt;
used from that script (using sys.path.append) that script will no longer have the ability to resolve these interface names.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I have a few python script under (let say) C:\python_scripts, these are mostly helpers and classes (e.g. ImporterReporter)&lt;/li&gt;
&lt;li&gt;I have another python script under C:\codesys_python\execute.py that should do some testing (or loggin in, etc)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;execute.py:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;python_scripts'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;python_importer&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This line gives me an error/exception that undefined name is&lt;br/&gt;
 -&amp;gt; execute.py line 2 "Unknown name"&lt;br/&gt;
 -&amp;gt; python_scripts\codesys_importer.py line 16 "ImporterReporter"&lt;/p&gt;
&lt;p&gt;Is there any way to grant access/visibility to script outside the runtime frame?&lt;br/&gt;
If I copy these scripts near my "execute.py" it works, but I have a reason for separating them&lt;br/&gt;
so that is not an option.&lt;/p&gt;
&lt;p&gt;Thank you very much for your help!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#4172" rel="alternate"/><published>2020-02-27T14:53:13.737000Z</published><updated>2020-02-27T14:53:13.737000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.comf3cde1d8e49d368f626fa432e671981090b30ff2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; M.Schaber&lt;/p&gt;
&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;First, we should stop discussing questions in this thread - it was only meant to present examples. We should create a new thread in this forum. &lt;/p&gt;
&lt;p&gt;Currently, it is not possible to suppress this dialog. We have system.prompt_answers which allows catching and auto-answering of dialogs - however, this currently works only for dialogs which have a so-defined "MessageKey", and it seems that the export dialogs don't offer such MessageKeys.&lt;/p&gt;
&lt;p&gt;I created issue CDS-25228 in our tracker so this will be fixed eventually.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#3989" rel="alternate"/><published>2020-02-27T14:53:13.076000Z</published><updated>2020-02-27T14:53:13.076000Z</updated><author><name>aoj</name><uri>https://forge.codesys.com/u/aoj/</uri></author><id>https://forge.codesys.com6f7b0a76f3d5c1fa6a389ccf94c89b8c77a0f860</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Hi,&lt;/p&gt;
&lt;p&gt;one more request &lt;br/&gt;
After exporting the project as XML-File, CoDeSys schows usually a message, that the exporting was successfull (&lt;strong&gt;Exportieren erfolgreich abgeschlossen&lt;/strong&gt;) and waits for the user to press the "OK" button. &lt;/p&gt;
&lt;p&gt;Is it possible to tell CoDeSys to continue executing the script without waiting for the "OK" button?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scripting - examples and receipes</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6d3d5de2c2/?limit=25&amp;page=1#786f" rel="alternate"/><published>2020-02-27T14:53:12.341000Z</published><updated>2020-02-27T14:53:12.341000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.comb1998c2b29267839bf436537f4bde77144ff1615</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; M.Schaber&lt;/p&gt;
&lt;p&gt;One of our customers works with "prototype projects". They want to slice the prototype projects into single objects, and then use those pieces to re-assemble different projects using scripts.&lt;/p&gt;
&lt;p&gt;While assisting our customer, the following example script was written. It exports all POUs of the project - each of them into a single file containing just that POU including its children (Actions, Properties etc.), and the parent folders to preserve the folder structure.&lt;/p&gt;
&lt;p&gt;Other scripts can then use the native import to import those objects under an Application, and the folder structure is recreated.&lt;/p&gt;
&lt;p&gt;(There is a Bug with native import that can lead to duplicated folders, the fix is scheduled for 3.4 SP4 Patch 2.)&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;\&lt;span class="c1"&gt;# Tests CoDeSys native import/export functionality.&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;__future__&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;print_function&lt;/span&gt;
&lt;span class="n"&gt;proj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;projects&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;primary&lt;/span&gt;
\&lt;span class="c1"&gt;# We're interested in POU nodes:&lt;/span&gt;
&lt;span class="n"&gt;POUGuid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Guid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"6f9dac99-8de1-4efc-8465-68ac443b7d08"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
\&lt;span class="c1"&gt;# We collect all POU nodes in that list.&lt;/span&gt;
&lt;span class="n"&gt;pous&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
\&lt;span class="c1"&gt;# From the parent node on, we recursively add POU nodes:&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;CollectPous&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;POUGuid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;pous&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;child&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_children&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;CollectPous&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;child&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
\&lt;span class="c1"&gt;# Now we collect all the leaf nodes.&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;proj&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_children&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;CollectPous&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
\&lt;span class="c1"&gt;# We print everything just to know what's going on.&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;pous&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"found: "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;guid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_name&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
\&lt;span class="c1"&gt;# And now we export the files.&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;pous&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="c1"&gt;# We create a list of objects to export:&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="c1"&gt;# The object itsself&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;objects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; 
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="c1"&gt;# And sub-objects (POUs can have actions, properties, ...)&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_children&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; 
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="c1"&gt;# And the parent folders.&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_folder&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; 
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="c1"&gt;# Create an unique file name:&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"d:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s2"&gt;__&lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s2"&gt;.export"&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_name&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;guid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; 
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="c1"&gt;# print some user information&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"exporting "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s2"&gt;" objects to: "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; 
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="c1"&gt;# and actually export the project.&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;proj&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;export_native&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"script finished."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry></feed>