scottd
(Scott Davidson)
March 16, 2021, 3:27pm
1
We are announcing a new component we are testing. Call into CPython with a Grasshopper component.
Some advantages of this component:
Call into CPython libraries including Numpy and SciPy
Use some of the newest libraries available for CPython such as TensorFlow.
Create re-usable functions and parallel processing.
Supports real debugging modes including breakpoints.
Full support of Visual Studio Code.
Give it a try if you are interested.
Getting started with CPython in Grasshopper.
This python module helps you create python (specifically CPython) functions and use them inside your Grasshopper scripts using the new Hops components.
Required:
Rhino 7.4 or newer.
CPython 3.8 or above
Hops Component for Grasshopper
Visual Studio Code highly recommended
Video Tutorial:
For more information and examples see the ReadMe on GH Hops CPython project
This module can use its built-in default HTTP server to serve the functions as Grasshopper components, or act as a middleware to a Flask app. It can also work alongside Rhino.Inside.CPython to give full access to the RhinoCommon API
72 Likes
Very exciting ! Will it be possible to use the same approach from the Rhino python editor outside grasshopper?
scottd
(Scott Davidson)
March 16, 2021, 5:47pm
4
At this point, the Python editor is outside Rhino. The example shows using Visual Studio Code, but other Python editors are possible to use.
Using the built-in Rhino editor is a different project that would only come in the future.
1 Like
I mean having a script running in rhino via RunPythonScript
which communicates with an external Cpython script, with no GrassHopper in the loop… For instance I frequently have to swap between Matlab files (which I can write with Scipy in Cpython) and Rhino geometry (which I manipulate, query with Ironpython outside Grasshopper)
2 Likes
stevebaer
(Steve Baer)
March 16, 2021, 6:02pm
6
Dancergraham:
I mean having a script running in rhino via RunPythonScript
which communicates with an external Cpython script, with no GrassHopper in the loop… For instance I frequently have to swap between Matlab files (which I can write with Scipy in Cpython) and Rhino geometry (which I manipulate, query with Ironpython outside Grasshopper)
I don’t see this working in the workflow of RunPythonScript
, but we definitely could make it work like a Rhino command with a little effort. The same that we showed with getting a curve and a number and then returning a point could be made into a command that asked for a curve and a number and then added a point to the Rhino document.
2 Likes
To be clear I am definitely not asking to use the Rhino Python editor in place of my current external python editor (Pycharm)
bachman
(Bachman)
March 17, 2021, 1:28am
8
Any news on when this might work with Rhino for Mac?
stevebaer
(Steve Baer)
March 17, 2021, 1:33am
9
Sure, today
This should work on both Windows and Mac Rhino/Grasshopper
Can this work inside Blender to send data?
2 Likes
stevebaer
(Steve Baer)
March 17, 2021, 3:31am
11
I would imagine so, but @nathanletwory would probably have a better idea of possible issues. We might need to tweak the ghhops-server library a little bit.
1 Like
jfreund
(Joseph Freund)
March 17, 2021, 4:03am
12
This is great, thanks. I copied Ehsan’s python script and I am getting this error from the Hops component:
Object 'Hops' {c69bb52c-88ba-4640-b69f-188d111029e8} failed to deserialize itself: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Resthopper.IO.IoParamSchema]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'Outputs.Name', line 1, position 409.
The response at http://127.0.0.1:5000/pointat is:
{"Description": "Get point along curve", "Inputs": [{"Name": "Curve", "Nickname": "C", "Description": "Curve to evaluate", "ParamType": "Curve", "ResultType": "Rhino.Geometry.Curve", "AtLeast": 1, "AtMost": 1}, {"Name": "t", "Nickname": "t", "Description": "Parameter on Curve to evaluate", "ParamType": "Number", "ResultType": "System.Double", "AtLeast": 1, "AtMost": 1}], "Outputs": [{"Name": "p", "Nickname": "p", "Description": "Point on curve at t", "ParamType": "Point", "ResultType": "Rhino.Geometry.Point3d", "AtLeast": 1, "AtMost": 1}], "Icon": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAHdElNRQfgCRALOQ37+ZoqAAAAB3RFWHRBdXRob3IAqa7MSAAAAAx0RVh0RGVzY3JpcHRpb24AEwkhIwAAAAp0RVh0Q29weXJpZ2h0AKwPzDoAAAAOdEVYdENyZWF0aW9uIHRpbWUANfcPCQAAAAl0RVh0U29mdHdhcmUAXXD/OgAAAAt0RVh0RGlzY2xhaW1lcgC3wLSPAAAACHRFWHRXYXJuaW5nAMAb5ocAAAAHdEVYdFNvdXJjZQD1/4PrAAAACHRFWHRDb21tZW50APbMlr8AAAAGdEVYdFRpdGxlAKju0icAABDLSURBVGhDNdkFsFVlFAXg/d4RG8UWi7ADCyQsEFHEwMZCERMLlQEMZvSogAXqKMZgg4kKKgo2CKJgd7egGBiIifo83545d+bNu+/cc/5/77XXWnv/9zXsvPPOTUVRxFJLLRU//fRTLLfccvHRRx/FeuutF6usskr+fvrpp2PJJZeMXXfdNdZYY4245ZZborGxMU466aT45ptvYvfdd48hQ4bERhttFJ988klstdVW+fmiRYvi3Xffje+//z769u0bn332WSxYsCBatGgRF1xwQZRlGQceeGBcfPHF0aVLl/j444/j+uuvj4ULF8aRRx4Zyy67bDQ0NMQ+++wTL7zwQnzwwQex5ZZbxk033RQXXnhhvPTSS9Hoph9++CF++eWXWLx4cay77rqxww475INVcrH++uvHyiuvHKuuumrce++9MW3atDj88MMzuIkTJ8Zrr72WAT3wwAOZpOc7d+4c//33X667/PLLR48ePeLxxx+PTz/9ND7//PMAGHA6dOiQ673xxhuxyy67xEorrRTXXHNNDB06NLbZZpto2bJlbLzxxvHee+/Fn3/+GRtssEHGImYJNW/ePBo322yzOPnkkxOBFVZYIbPcdtttE7V///03pk+fnpWB7GqrrZbBCPqggw6KP/74I+bOnRvDhw/PAAT7yiuvZBDu8YLY6quvHl999VVWxvtvv/02g7ntttuiWbNm8eqrr8aaa66ZFfjtt99i6623TgDcZ4899tgjq6SCBx98cPz66695/++//x5FFVT59ttvR8eOHePLL7+MVq1aRadOnfLhOXPmZCWOOeaYePnll2PfffeNqVOnZtBHH310PP/889G2bdv4+++/M9hNN900KShI16B9/PHHZ3UlJtATTjgh11YFlfvxxx/z/WWXXRZdu3ZNukoKaOgKMPuj6DLLLJMgAee5555LEIp11lmnFHTv3r3jrbf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KBrztYqU1wUnfV8DQyaGj/npOsctOJAFFI90Qt7uLEZXqEmuRVV5dHWxUzK7mf+PUetHG/7us+ItYfgGvAdJb2Em9RUSj/S8ktBON9/Z96FMBdJYWqQ7TFawqxtnqwg7aSAoC7uA5p6+Cvz4iaNQuIWP1NnKhpFuNMeG5EIG5xSFhFjCIcCw3F6F/BYiqqzfL/xNDANxfxD+cFazOfoYAEBWoo4/ECQzPUIEYW617V8j+ueqzQRc06ELa251BEtxWQHzRWXQCorDOBz02smhYKs28VRTnOJbGiKnl+uWtTjmJx5dSoUIPoOIcDicDrbyUkaK6hA83MP7MtqNmhF0FKRqBAQFUnLfbLJIwfzgfWsp9qCVSnNshprq6pOjpLiOvoV6jouXnz5sX/itWo5RRH2B4AAAAASUVORK5CYII="}
I am using Python 3.9.1 in VSCode, Rhino 7.4.21067.13001 and Hops 0.4.5. Any help is greatly appreciated.
Thanks,
JF
stevebaer
(Steve Baer)
March 17, 2021, 4:17am
13
Can you send me the python script you wrote? I would like to see if I can repeat this and figure out a more useful error message to provide.
By the way, a version of what Ehsan wrote is available at
"""Hops flask middleware example"""
from flask import Flask
import ghhops_server as hs
import rhino3dm
# register hops app as middleware
app = Flask(__name__)
hops: hs.HopsFlask = hs.Hops(app)
# flask app can be used for other stuff drectly
@app.route("/help")
def help():
return "Welcome to Grashopper Hops for CPython!"
@hops.component(
"/binmult",
inputs=[hs.HopsNumber("A"), hs.HopsNumber("B")],
This file has been truncated. show original
bachman
(Bachman)
March 17, 2021, 6:25am
14
I don’t see a way to install Hops on Rhino for Mac. Am I missing it? It’s not showing up in package manager.
bachman
(Bachman)
March 17, 2021, 6:29am
15
Ah. Sorry. I was using the Rhino 8 WIP. I see it in Rhino 7. I assume this will make it to the WIP soon?
Looking forward to playing with it!
mistrymm7
(Mistrymm7)
March 17, 2021, 6:36am
16
This is incredible. It will open up so many possibilities with grasshopper
1 Like
Can’t wait to dig into this, unfortunately haven’t been able to install the ghhops server via the Quick Start guide. I received a massive set of error messages in my command line when pip install ghhops-server. (see image attached)
I’m using:
Python 3.9
Rhino (7.4.21067.13001, 2021-03-08)
ghhops 0.4.5
Any advice for troubleshooting?
Thanks!
mistrymm7
(Mistrymm7)
March 17, 2021, 11:40am
18
@kai , looks like its throwing error related to rhino3dm. maybe installing rhino3dm might help.
1 Like
mistrymm7
(Mistrymm7)
March 17, 2021, 11:41am
19
Couldnt wait doing some experiments with it. Developed some components in gh using opencv.
6 Likes
stevebaer
(Steve Baer)
March 17, 2021, 11:43am
20
kai.aurelien.zhu:
I’m using:
Python 3.9
Rhino (7.4.21067.13001, 2021-03-08)
ghhops 0.4.5
The errors are coming from a 32 bit version of python 3.8 on your system. We may not be currently supporting 32 bit builds for python with rhino3dm; I would need to double check. Is there a reason you need 32 bit python?
If you think you are using Python 3.9, maybe you can uninstall this older 32 bit Python 3.8
1 Like