Hello,
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,
Daniel
Hello,
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,
Daniel
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 : https://docs.python.org/3.7/library/ctypes.html
# 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):
pass
# 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)
self.outputs["out"].write(bvar)
# Death() will be called once at diagram execution shutdown
def Death(self):
pass
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.
G.
I have found the samples indeed. Thanks a lot !