<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to How to run python script via plugin?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/</id><updated>2020-02-27T14:49:06.536000Z</updated><subtitle>Recent posts to How to run python script via plugin?</subtitle><entry><title>How to run python script via plugin?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/?limit=25#80f4" rel="alternate"/><published>2020-02-27T14:49:06.536000Z</published><updated>2020-02-27T14:49:06.536000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com797288ad22302f8fbb34ae1616fba98e577bd039</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;blockquote&gt;
&lt;p&gt;&lt;strong&gt;andipandi hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Could that be&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;            &lt;span class="nv"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;scriptEngine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;IScriptEngine&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;ComponentManager&lt;/span&gt;.&lt;span class="nv"&gt;Singleton&lt;/span&gt;.&lt;span class="nv"&gt;InstanceFactory&lt;/span&gt;.&lt;span class="nv"&gt;GetSystemInstance&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;typeof&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;IScriptEngine&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;.&lt;span class="nv"&gt;FullName&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;scriptEngine&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nv"&gt;null&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
                &lt;span class="nv"&gt;throw&lt;/span&gt; &lt;span class="nv"&gt;new&lt;/span&gt; &lt;span class="nv"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No ScriptEngine accessible error.&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
            &lt;span class="nv"&gt;scriptEngine&lt;/span&gt;.&lt;span class="nv"&gt;Execute&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;abc.py&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;?&lt;br/&gt;
Also, if I have this running in a plugin (that is the way to do it?) in a separate thread, can I just call the Execute method or is there some dependency on the main thread?&lt;br/&gt;
Many thanks&lt;/p&gt;
&lt;p&gt;Yes, that source looks like a valid, minimal script execution.&lt;/p&gt;
&lt;p&gt;For more control about the script, you can create an IScriptExecutor.&lt;/p&gt;
&lt;p&gt;IronPython by itself does not depend on the main thread, it is (or should be) as threading capable as other .NET languages like C#.&lt;/p&gt;
&lt;p&gt;However, the standard scripting API we provide to the scripts using the script drivers is inherently bound to the primary thread (UI thread), as it calls into Automation Platform APIs.&lt;/p&gt;
&lt;p&gt;If you do not want to use that API, just use an IScriptExecutor and don't call the "LoadScriptDrivers()" Method. Then your scripts can still use the whole .NET and IronPython standard library, as well as any APIs you provide or any Assemblies the script loads directly.&lt;/p&gt;
&lt;p&gt;HTH,&lt;br/&gt;
Markus&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to run python script via plugin?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/?limit=25#8342" rel="alternate"/><published>2020-02-27T14:49:04.671000Z</published><updated>2020-02-27T14:49:04.671000Z</updated><author><name>andipandi</name><uri>https://forge.codesys.com/u/andipandi/</uri></author><id>https://forge.codesys.com0baa929ea71cb5ae620bfa32ff5d834740e3ab98</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Could that be&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;            &lt;span class="nv"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;scriptEngine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;IScriptEngine&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;ComponentManager&lt;/span&gt;.&lt;span class="nv"&gt;Singleton&lt;/span&gt;.&lt;span class="nv"&gt;InstanceFactory&lt;/span&gt;.&lt;span class="nv"&gt;GetSystemInstance&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;typeof&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;IScriptEngine&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;.&lt;span class="nv"&gt;FullName&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;scriptEngine&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nv"&gt;null&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
                &lt;span class="nv"&gt;throw&lt;/span&gt; &lt;span class="nv"&gt;new&lt;/span&gt; &lt;span class="nv"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No ScriptEngine accessible error.&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
            &lt;span class="nv"&gt;scriptEngine&lt;/span&gt;.&lt;span class="nv"&gt;Execute&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;abc.py&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;?&lt;/p&gt;
&lt;p&gt;Also, if I have this running in a plugin (that is the way to do it?) in a separate thread, can I just call the Execute method or is there some dependency on the main thread?&lt;/p&gt;
&lt;p&gt;Many thanks&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to run python script via plugin?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/?limit=25#d888" rel="alternate"/><published>2020-02-27T14:49:04.092000Z</published><updated>2020-02-27T14:49:04.092000Z</updated><author><name>andipandi</name><uri>https://forge.codesys.com/u/andipandi/</uri></author><id>https://forge.codesys.com1f181c2d3e0887920bbfabae793a45c509ce320a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;a class="user-mention" href="/u/etamgul/"&gt;@etamgul&lt;/a&gt;&lt;br/&gt;
Many thanks, I probably was not clear enough in my description, I was wondering how to execute a script within Codesys - controlled from another program.&lt;/p&gt;
&lt;p&gt;@Markus&lt;br/&gt;
Many thanks, that is what I am looking for.&lt;br/&gt;
Since from my understanding, the plugin is passive, I would then have to create my own listener in that plugin in order to control it from outside the Codesys application.&lt;/p&gt;
&lt;p&gt;Your sample unfortunately is the other way round.. extending the script engine, but not controlling it.&lt;/p&gt;
&lt;p&gt;(Sorry, I have not developed with the Codesys plugin concept yet.)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to run python script via plugin?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/?limit=25#bd3e" rel="alternate"/><published>2020-02-27T14:49:03.519000Z</published><updated>2020-02-27T14:49:03.519000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com775c0b2dc3b6c8b010895b52a00180a23b49c95f</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, Andreas,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;andipandi hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Dear Forum!&lt;br/&gt;
Following up on &lt;a class="" href="http://forum.codesys.com/viewtopic.php?f=18&amp;amp;t=6115" rel="nofollow"&gt;http://forum.codesys.com/viewtopic.php?f=18&amp;amp;t=6115&lt;/a&gt; (which I hijacked, sorry), I am wondering:&lt;br/&gt;
Is it possible to programmatically start a Python script via a plugin?&lt;br/&gt;
I. e. can I write a plugin that has a method that makes Codesys execute a Python script, e. g. based on its path? (I would then create another interface to that plugin, like a web service, in order to execute different Python scripts when feasible.)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With programmatically, I think you mean the Automation Platform.&lt;/p&gt;
&lt;p&gt;The ScriptEngine Plugin has an official Automation Platform API which allows to start your own scripts. (This is also what the Test Manager does within its "ExecuteScript" action.) This API provides more control than using the command execution.&lt;/p&gt;
&lt;p&gt;The apis are defined in the ScriptEngine interface DLL.&lt;/p&gt;
&lt;p&gt;There's also an &lt;a class="" href="http://dn.codesys.com/samples/details/s17-creating-a-scriptable-plug-in/" rel="nofollow"&gt;article in the developer network&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;HTH,&lt;br/&gt;
Markus&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to run python script via plugin?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/?limit=25#1cf9" rel="alternate"/><published>2020-02-27T14:49:01.952000Z</published><updated>2020-02-27T14:49:01.952000Z</updated><author><name>etamgul</name><uri>https://forge.codesys.com/u/etamgul/</uri></author><id>https://forge.codesys.comb12a6bf20715e0973055e544246e344dc696ad7c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Also you can experiment with system execute command as described here:&lt;br/&gt;
  l &lt;a class="" href="http://forum.codesys.com/viewtopic.php?f=18&amp;amp;t=6306" rel="nofollow"&gt;viewtopic.php?f=18&amp;amp;t=6306&lt;/a&gt; l &lt;/p&gt;
&lt;p&gt;the GUID/names you need is:&lt;br/&gt;
974e36d0-d2ed-4dcc-9505-2e4f2fb9c70d - Execute Script File... - Array&lt;a class="" href="../('script',%20'execute')"&gt;str&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;so:&lt;br/&gt;
system.commands&lt;span&gt;[GUID('974e36d0-d2ed-4dcc-9505-2e4f2fb9c70d')]&lt;/span&gt;.execute(...)&lt;/p&gt;
&lt;p&gt;or identical:&lt;br/&gt;
system.commands&lt;span&gt;["script", "execute"]&lt;/span&gt;.execute(...)&lt;/p&gt;
&lt;p&gt;I dont know:&lt;br/&gt;
 - if this can be execute without GUI (--noUI) execution&lt;br/&gt;
 - if execute() takes an argument&lt;br/&gt;
 - if it does not you have to use additional methods to pass the path of the script to codesys (maybe system.prompt_answers&lt;span&gt;[...]&lt;/span&gt;)&lt;/p&gt;
&lt;p&gt;Sorry I dont have the time to experiment with these. But thought it can help you.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to run python script via plugin?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/?limit=25#4bd9" rel="alternate"/><published>2020-02-27T14:49:01.400000Z</published><updated>2020-02-27T14:49:01.400000Z</updated><author><name>etamgul</name><uri>https://forge.codesys.com/u/etamgul/</uri></author><id>https://forge.codesys.coma4af9ae43b9ea5add8942ba9f07ded4e2ea60b6a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I'm replying as a user so dont take my word as an answer.&lt;/p&gt;
&lt;p&gt;What you could use is 'execfile(path_to_your_script);' this is similar to C include (it will put the content of the script/file you pass&lt;br/&gt;
to the line where it is executed.&lt;/p&gt;
&lt;p&gt;With FIFO management you can create a python script (executed by codesys) which accepts pathes on your interface&lt;br/&gt;
and puts it in the FIFO, then an endless loop processes the the FIFO and calls the execfile with your scripts.&lt;/p&gt;
&lt;p&gt;This would maybe the simpliest, I dont know if it works I've never tried the execfile in a loop but im using this method&lt;br/&gt;
to exec multiple python script to the codesys executed one.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to run python script via plugin?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/60039f2d35/?limit=25#9068" rel="alternate"/><published>2020-02-27T14:49:00.842000Z</published><updated>2020-02-27T14:49:00.842000Z</updated><author><name>andipandi</name><uri>https://forge.codesys.com/u/andipandi/</uri></author><id>https://forge.codesys.comb83264aee99b1d35cdbe7c542f89d4fdeee9ae6a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Dear Forum!&lt;/p&gt;
&lt;p&gt;Following up on &lt;a class="" href="http://forum.codesys.com/viewtopic.php?f=18&amp;amp;t=6115" rel="nofollow"&gt;http://forum.codesys.com/viewtopic.php?f=18&amp;amp;t=6115&lt;/a&gt; (which I hijacked, sorry), I am wondering:&lt;/p&gt;
&lt;p&gt;Is it possible to programmatically start a Python script via a plugin?&lt;/p&gt;
&lt;p&gt;I. e. can I write a plugin that has a method that makes Codesys execute a Python script, e. g. based on its path? (I would then create another interface to that plugin, like a web service, in order to execute different Python scripts when feasible.)&lt;/p&gt;
&lt;p&gt;Many thanks&lt;br/&gt;
Andreas Reiff&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>