PythonEvaluate in Rhino.Compute

Has anyone experimented with compute_rhino3d.Util.PythonEvaluate(script, input, output)?
It’s supposed to take a python script as a string and evaluate that inside compute server and return the result, I just started playing around and it seems to exactly do that.
Well I tested it with a very basic example below:

script="""
c=a+b
"""
result = compute_rhino3d.Util.PythonEvaluate(script,{"a":3, "b":5},["c"])

And I get result = {c: 8}

But I’m running into issues trying to get non-text outputs out. For example:

script="""
import Rhino
plane = Rhino.Geometry.Plane.WorldXY
c = Rhino.Geometry.Circle(plane,r)
"""
result = compute_rhino3d.Util.PythonEvaluate(script,{"r":3},["c"])

Gives me the error below:

PythonEvaluate
    output = rhino3dm.ArchivableDictionary.DecodeDict(json.loads(response))
  File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 341, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '

Which I think means that the output is not the type expected.
My question is what’s the proper way to convert the circle in this case to an accepted type (str, bytes or bytearray) that can be decoded to rhino geometry later in the host application using rhino3dm.CommonObject.Decode(data) ?

I think this may be due to the fact that Rhino.Geometry.Circle does not inherit from GeometryBase (which, in turn, inherits from CommonObject). Circle is a lightweight circle defition, with plane+radius as its only data members.

Could you try the following:

c = Rhino.Geometry.Circle(plane, r).ToNurbsCurve()

This converts the Circle into a NurbsCurve object, which does inherit from GeometryBase and CommonObject.

3 Likes

Amazing, I can’t believe that was the issue. Thanks, solved my problem.

1 Like