Custom Types in Python Bridge


Is it possible to use custom types in the python bridge similar to the C++ SDK ?
I couldn’t find any documentation or sample specific for PythonBridge.
Could you help me please? Thanks.

Kind regards,

Hello Daniel,

Yes it is possible to create and read/write custom structure in a python bridge component. Actually there is a sample about that, located in in “packages\rtmaps_python_bridge\samples\Chapter2_Types_Creation”

Here is one of the code samples :

import rtmaps.types
from ctypes import *
import rtmaps.reading_policy
from rtmaps.base_component import BaseComponent  # base class

# This sample uses ctypes :
# This class mirrors a C struct and will be used to read a write from RAW bytes.
class MyCStyleStructType(Structure):
    _fields_ = [('a', c_int),
                ('b', c_int),
                ('c', c_int)]
    _pack_ = 1

# Python class that will be called from RTMaps.
class rtmaps_python(BaseComponent):
    def __init__(self):
        BaseComponent.__init__(self) # call base class constructor

    def Dynamic(self):
        # Here "Example" is the name of the custom struct generated
        self.add_output("out", rtmaps.types.CUSTOM_STRUCT, 0, "Example") # Specify output type

    # Birth() will be called once at diagram execution startup
    def Birth(self):

    # Core() is called every time you have a new input
    def Core(self):
        a = 7
        b = 21
        c = 666
        var = MyCStyleStructType(a, b, c) # Build structure

        bvar = bytes(var)

    # Death() will be called once at diagram execution shutdown
    def Death(self):

Just as a reminder, on top of the samples in the installation directory, we also have a PythonBridge video tutorial on YouTube.

Hope this helps.

I have found the samples indeed. Thanks a lot !