<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to build (F11) / generate code using a python script file</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/26b27aa0cf/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/26b27aa0cf/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/26b27aa0cf/</id><updated>2024-04-11T07:17:27.666000Z</updated><subtitle>Recent posts to build (F11) / generate code using a python script file</subtitle><entry><title>build (F11) / generate code using a python script file</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/26b27aa0cf/?limit=250#fe09" rel="alternate"/><published>2024-04-11T07:17:27.666000Z</published><updated>2024-04-11T07:17:27.666000Z</updated><author><name>dkugler</name><uri>https://forge.codesys.com/u/dkugler/</uri></author><id>https://forge.codesys.com12d0005af9d8c56a6e9a1353da4c99fba42b2fd9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;thank you very much! I found the generate_code methode, but struggled with the primary and active_application. With this expample I will be able to play around. If the code generation takes a minute or more I often switch to other programs and don't notify the process is finished. So now I'll get an alert and will switch back immediately. My next little project will be, to beep different if there are errors and a seperate script to do the download incl. the user management data base without stopping at the dialogs asking for onlinechange/complete download and overwriting an existing database and as goody, play a beep/sound again.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>build (F11) / generate code using a python script file</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/26b27aa0cf/?limit=25#b564" rel="alternate"/><published>2024-04-10T17:31:07.499000Z</published><updated>2024-04-10T17:31:07.499000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.comd7182db8a6bc23705194ffc1babc0ed840757d76</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;hello, please enjoy.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# i-campbell 2024&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;subprocess&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;scriptengine&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="c1"&gt;# with a project already open&lt;/span&gt;
&lt;span class="c1"&gt;# save if not yet saved&lt;/span&gt;
&lt;span class="c1"&gt;# check pool objects if it is a library&lt;/span&gt;
&lt;span class="c1"&gt;# generate code only for the active application if it is a project&lt;/span&gt;
&lt;span class="c1"&gt;# beep thanks to https://devblogs.microsoft.com/scripting/powertip-use-powershell-to-send-beep-to-console/&lt;/span&gt;

&lt;span class="k"&gt;if&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="p"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# check project is open&lt;/span&gt;
    &lt;span class="k"&gt;if&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="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dirty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# save&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="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;if&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="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;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.library'&lt;/span&gt;&lt;span class="p"&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="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;check_all_pool_objects&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# check all pool objects for lib&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&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="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active_application&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;generate_code&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# generate if not lib&lt;/span&gt;
        &lt;span class="c1"&gt;# note, there could be more applications than the active application,&lt;/span&gt;
        &lt;span class="c1"&gt;# this script does not generate those&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Severity&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'no project open'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ps_output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;check_output&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"powershell"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-Command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"[console]::beep(500,300)"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# beep&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</summary></entry><entry><title>build (F11) / generate code using a python script file</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/26b27aa0cf/?limit=250#766a" rel="alternate"/><published>2024-04-10T15:26:38.642000Z</published><updated>2024-04-10T15:26:38.642000Z</updated><author><name>dkugler</name><uri>https://forge.codesys.com/u/dkugler/</uri></author><id>https://forge.codesys.com7503895566be7a71b3529769d7e70c382d697a84</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;After a project is opened and I have done some changes, I want to start the build or code generating process by a python script file. After the build is done I a Windows sound/beep should appear. Anyone has an example or hint how the .py file has to look like? Thanks!&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>