CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Nov 12, 2019 9:27 am

All times are UTC+01:00

Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Jan 08, 2014 11:51 am 

Joined: Tue Jan 07, 2014 12:02 pm
Posts: 2
Good day,

I am trying to call and execute custom objects using python script and hope someone could help me out with that.
Currently with OnDriverLoad() I add an object to ScriptEngine which I call companyCommand. This companyCommand object
implements the IScripExecutor interface (C#) and has the function "execute".

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


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
where this is shown.

Best regards and Thank you,



I will be able to provide more information on the implementation when I am back at the office tomorrow.

PostPosted: Wed Jan 08, 2014 12:12 pm 
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, dsDeveloper,

First, this seems to be an Automation Platform question, which is best directed to the developer contact you got during your Automation Platform training.

The developer network has an article How to make a scriptable plugin 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.)

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.

In your IScriptDriver, during the OnDriverLoad() method, just pass in the objects you want to be accessible for the script:
public class ScriptDriverSystem : IScriptDriver
    public void OnDriverLoad(IScriptExecutor executor)
        // The script can access an instance of our CompanyObject() class by the name
        // company_object and call all its methods:
        executor.ProvideObjectForScript("company_object", new CompanyObject());

        // Some of our methods need the MyEnum parameter, so we provide the enum to the script.
        // Enums and other type objects which need to be accessible by the script (e. G. for instantiation and
        // calling of static methods) need to be passed through PrepareType - it creates a python type out of
        // the .NET Type object.
        executor.ProvideObjectForScript("MyEnum", executor.Engine.PrepareType(typeof(MyEnum)));

        // You can also provide functions directly, by creating delegates:
        executor.ProvideObjectForScript("company_function", new System.Action<int>(SomeMethod));

    public void SomeMethod(int i) { do something here... }

public enum MyEnum { ... }

public class CompanyObject { ... }

Check out the CODESYS store:

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions

PostPosted: Thu Jan 09, 2014 12:52 pm 

Joined: Tue Jan 07, 2014 12:02 pm
Posts: 2
Thank you for your reply, Schaber. I checked the website and my implementation and it seemed to be correct. My issue was
the way I passed arguments to a function of the company object. Python uses lists and an array was expected. I was using
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).

Thank you again for your effort!

Best regards,


Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 3 posts ] 

All times are UTC+01:00

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited