<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Execute custom object commands in python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/c87ee3c0a8/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/c87ee3c0a8/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/c87ee3c0a8/</id><updated>2020-02-27T15:01:22.584000Z</updated><subtitle>Recent posts to Execute custom object commands in python script</subtitle><entry><title>Execute custom object commands in python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/c87ee3c0a8/?limit=25#05d8" rel="alternate"/><published>2020-02-27T15:01:22.584000Z</published><updated>2020-02-27T15:01:22.584000Z</updated><author><name>dsDeveloper</name><uri>https://forge.codesys.com/u/dsdeveloper/</uri></author><id>https://forge.codesys.com1e33b580ec69f37ca5251067e0404d7889d99fef</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thank you for your reply, Schaber. I checked the website and my implementation and it seemed to be correct. My issue was&lt;br/&gt;
the way I passed arguments to a function of the company object. Python uses lists and an array was expected. I was using&lt;br/&gt;
params in the C# code, so just passing the arguments one by one was the solution. Now it works as it should (at least this step).&lt;/p&gt;
&lt;p&gt;Thank you again for your effort!&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;dsDeveloper&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Execute custom object commands in python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/c87ee3c0a8/?limit=25#cd2e" rel="alternate"/><published>2020-02-27T15:01:21.913000Z</published><updated>2020-02-27T15:01:21.913000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com2c31fc48027cd53fec05f725296c1cc69662a712</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, dsDeveloper,&lt;/p&gt;
&lt;p&gt;First, this seems to be an Automation Platform question, which is best directed to the developer contact you got during your Automation Platform training.&lt;/p&gt;
&lt;p&gt;The developer network has an article &lt;a class="" href="http://dn.codesys.com/de/node/83" rel="nofollow"&gt;How to make a scriptable plugin&lt;/a&gt; which explains the basics of creating scriptable plugins. (If you don't have an account yet, create one, and contact your 3S Sales Rep. to enable access to the AP section.)&lt;/p&gt;
&lt;p&gt;The IScriptExecutor interface is implemented by the Script Engine, and other Automation Platform plugins use it to trigger the execution of scripts. It is not to be implemented by objects which are provided for the scripts - those object should just provide the interface to be used by the scripts.&lt;/p&gt;
&lt;p&gt;In your IScriptDriver, during the OnDriverLoad() method, just pass in the objects you want to be accessible for the script:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;[TypeGuid("{insert-your-guid-here}")]&lt;/span&gt;
&lt;span class="na"&gt;public class ScriptDriverSystem : IScriptDriver&lt;/span&gt;
&lt;span class="na"&gt;{&lt;/span&gt;
&lt;span class="na"&gt;    public void OnDriverLoad(IScriptExecutor executor)&lt;/span&gt;
&lt;span class="na"&gt;    {&lt;/span&gt;
&lt;span class="na"&gt;        // The script can access an instance of our CompanyObject() class by the name&lt;/span&gt;
&lt;span class="na"&gt;        // company_object and call all its methods:&lt;/span&gt;
&lt;span class="na"&gt;        executor.ProvideObjectForScript("company_object", new CompanyObject());&lt;/span&gt;
&lt;span class="na"&gt;        // Some of our methods need the MyEnum parameter, so we provide the enum to the script.&lt;/span&gt;
&lt;span class="na"&gt;        // Enums and other type objects which need to be accessible by the script (e. G. for instantiation and &lt;/span&gt;
&lt;span class="na"&gt;        // calling of static methods) need to be passed through PrepareType - it creates a python type out of&lt;/span&gt;
&lt;span class="na"&gt;        // the .NET Type object.&lt;/span&gt;
&lt;span class="na"&gt;        executor.ProvideObjectForScript("MyEnum", executor.Engine.PrepareType(typeof(MyEnum)));&lt;/span&gt;
&lt;span class="na"&gt;        // You can also provide functions directly, by creating delegates:&lt;/span&gt;
&lt;span class="na"&gt;        executor.ProvideObjectForScript("company_function", new System.Action&amp;lt;int&amp;gt;(SomeMethod));&lt;/span&gt;
&lt;span class="na"&gt;    }&lt;/span&gt;
&lt;span class="na"&gt;    public void SomeMethod(int i) { do something here... }&lt;/span&gt;
&lt;span class="na"&gt;}&lt;/span&gt;
&lt;span class="na"&gt;public enum MyEnum { ... }&lt;/span&gt;
&lt;span class="na"&gt;public class CompanyObject { ... }&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Execute custom object commands in python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/c87ee3c0a8/?limit=25#a8ee" rel="alternate"/><published>2020-02-27T15:01:21.257000Z</published><updated>2020-02-27T15:01:21.257000Z</updated><author><name>dsDeveloper</name><uri>https://forge.codesys.com/u/dsdeveloper/</uri></author><id>https://forge.codesys.comcaa33d4f257d628b069b23ba9216ae2599a72f68</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Good day,&lt;/p&gt;
&lt;p&gt;I am trying to call and execute custom objects using python script and hope someone could help me out with that. &lt;br/&gt;
Currently with OnDriverLoad() I add an object to ScriptEngine which I call companyCommand. This companyCommand object&lt;br/&gt;
implements the IScripExecutor interface (C#) and has the function "execute".&lt;/p&gt;
&lt;p&gt;Now if I want to call that function in a pythong script which I passed to the .exe, how do I need to proceed? Is it enough to add&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;companyCommand&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;and also pass the GUID of the object or do I need to call it in a special way? Any imports necessary? I couldn't find a tutorial&lt;br/&gt;
where this is shown.&lt;/p&gt;
&lt;p&gt;Best regards and Thank you,&lt;/p&gt;
&lt;p&gt;dsDeveloper&lt;/p&gt;
&lt;p&gt;P.S.&lt;/p&gt;
&lt;p&gt;I will be able to provide more information on the implementation when I am back at the office tomorrow.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>