Custom types between CPython hops components

Hey,

Here’s another question about Cpython Hops
Will it ever support custom types?

The first Hops component cannot use the repr function so pass to Grasshopper.
And even if it did, I guess the Hops input type of the second component would need something else than the hs.HopsString type.


Here’s the basic Hops version

from flask import Flask
import ghhops_server as hs


app = Flask(__name__)
hops: hs.HopsFlask = hs.Hops(app)


class HelloWorld:
	def __init__(self, count):
		self.message = "Hello World"
		self.count = count
	
	def __repr__(self):
	    return "repr lives matter"

	

@hops.component(
    "/class",
    name = "Class repr test",
    nickname = "repr test",
    description = "Test the repr of a class",
    inputs = [
        hs.HopsInteger("Count", "C", "Count of hello worlds")
    ],
    outputs = [
        hs.HopsString("Repr", "R", "Repr of the class")
    ]
)
def test_repr(counter):
	return HelloWorld(counter)


@hops.component(
	"/message",
	name = "Message",
	nickname = "Message",
	description = "Prints a message multiple times",
	inputs = [
	    hs.HopsString("Repr", "R", "Would read the object, not the repr string")
	],
	outputs = [
        hs.HopsString("Messages", "M", "Messages printed a number of times")
    ]
)
def messages(my_object):
	return [my_object.message] * int(my_object.count)


if __name__ == "__main__":
	app.run(debug=False)

@stevebaer, let me know if I should tag someone else instead :slight_smile:

This might be possible now by using pickle on python classes and then base64 encoding that pickled object into a string.

I’m not sure how good pickle support is between IronPython and CPython. This issue will go away in Rhino 8 when we have scripting options for CPython in GH.

I’ll have a look into that while waiting for Rhino8 then :slight_smile:

Thanks for the suggestion !