Using Hops, how to pass 3dm object back to Rhino?

Hello, I’m trying to use the rhino3dm in python for some geometry operation outside rhino, and link it through “hops” component.

However, when passing Polyline back with hops, I got the error:

1. Exception occured in handler:
Object of type Polyline is not JSON serializable
  File "c:\Users\zhma.ARCH-GALI-W-01\miniforge3\envs\rhino\lib\site-packages\ghhops_server\params.py", line 240, in from_result
    output_list = [

  File "c:\Users\zhma.ARCH-GALI-W-01\miniforge3\envs\rhino\lib\site-packages\ghhops_server\params.py", line 241, in <listcomp>
    {"type": self.result_type, "data": RHINO_TOJSON(CONVERT_VALUE(v))}

  File "c:\Users\zhma.ARCH-GALI-W-01\miniforge3\envs\rhino\lib\site-packages\ghhops_server\params.py", line 116, in to_json
    return json.dumps(value, cls=_HopsEncoder)

  File "c:\Users\zhma.ARCH-GALI-W-01\miniforge3\envs\rhino\lib\json\__init__.py", line 234, in dumps
    return cls(

  File "c:\Users\zhma.ARCH-GALI-W-01\miniforge3\envs\rhino\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)

  File "c:\Users\zhma.ARCH-GALI-W-01\miniforge3\envs\rhino\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)

  File "c:\Users\zhma.ARCH-GALI-W-01\miniforge3\envs\rhino\lib\site-packages\ghhops_server\base.py", line 343, in default
    return json.JSONEncoder.default(self, o)

  File "c:\Users\zhma.ARCH-GALI-W-01\miniforge3\envs\rhino\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '

It seems Hops use Json to pass object between the Flask Server and Rhino. When it works for passing Polyline object out from Rhino, how to pass it back?

OK, I need to convert it to PolylineCurve so that it is Json Serializable…
Interesting.

1 Like