Ventuz3 .net remoting with python - part 1

ventuzpynet.jpg

VENTUZ3 .NET REMOTING WITH PYTHON - PART 1

If you've written a lot of code in python and it scares you to switch over to C# to get/set properties and invoke methods inside a Ventuz scene or to use all this in a multi scene environment there is a solution for you - IronPython (Microsofts python derivate) supports the .NET Framework and you can import classes and methods from .dll files. //Get the installer here

In this two-part post I am going to show some getting/setting properties & invoking methods in a one scene setup (part 1) and extend all this to interact with a multi scene environment (part 2). I expect the reader to have some previous knowledge in .net remoting with Ventuz.

The class I provide implements the basic connect, get/set property and execute method functions.

As you can read in the Ventuz .net remoting documentation theres a lot more functionality than that. Like event handling, scheduling and error handling. This might be the topic of a further post.

After you've installed IronPython either start IronPython Console from start menu or type ipy in the command line tool.

import sys
import clr 

sys.path.append("C:/Programme/Ventuz Technology Group/Ventuz 3 (x64)") 
#tell ipy where the remoting .dlls are 
clr.AddReference("Ventuz.Kernel.Remoting") #Ventuz.Kernel.Remoting.dll
clr.AddReference("Ventuz.Kernel.Remoting.Tools")#Ventuz.Kernel.Remoting.Tools.dll

from System import Array
from Ventuz.Kernel.Remoting import*
from Ventuz.Remoting2.Helpers import*


class VentuzScene:
    def __init__(self, host, sceneName):
        _venSys = RemoteScene.Connect(host)
        self.scene = _venSys.LoadScene(sceneName)
        when = RemoteScene.IMMEDIATE
        _venSys.Ports[0].SetScene(self.scene, when, None)
        _venSys.Ports[0].SetActive(True, when, None)
    def ChangeProperty(self, properties, values):
        p = Array[str](properties)
        v = Array[object](values)
        when = RemoteScene.IMMEDIATE
        self.scene.SetPropertiesInvokeMethods(p, v, None, None, when, None )
    def FireMethod(self, methods, arguments):
        m = Array[str](methods)
        a = Array[int](arguments)
        when = RemoteScene.IMMEDIATE
        self.scene.SetPropertiesInvokeMethods(None, None, m, a, when, None )
    def GetProperty(self, properties):
        p = Array[str](properties)
        return list(self.scene.GetProperties(p))

As my scene is running on the same system, and I didn't change the standard .net port (19200) I can connect with "localhost" to "scene1". Remind the "/" prefix to the scene name. You should either refer to the remoting section in ventuz help or read the .net remoting documentation in your installation directory to find out more about this feature!!

>>>
>>> Scene = VentuzScene("localhost","/scene1")
>>>


Methods can also take arguments, handed over in an Array[n]([])

>>>
>>> Scene.ChangeProperty(["/Text"],["Hello World"])
>>> Scene.GetProperty(["/Text"])
['Hello World']
>>>
>>> Scene.ChangeProperty(["/Text","/Text2","/Text3"],["ABCD","abcd","1234"])
>>> Scene.GetProperty(["/Text","/Text2","/Text3"])
['ABCD','abcd','1234']

Methods can be invoked like this:

>>>
>>> Scene.ChangeProperty(["/Text"],["Hello World"])
>>> Scene.GetProperty(["/Text"])
['Hello World']
>>>
>>> Scene.FireMethod(["/Nudge"])
>>>

Conclusion:

Of course all of the above can also be achieved through OSC remoting, but when it comes to scene management there is no way around native .net remoting. In part 2 I will control methods and properties of dynamically loaded scenes.

Client

MediaScreen GmbH

Technology

Ventuz3, python, Remoting2