GH Python Remote is a package to get Rhinoceros3D/Grasshopper and Python to collaborate better: connect an external python instance to Grasshopper, and vice-versa.
Requires a Python 2.7 installation, not compatible with Python 3. Python 2.6 might work but is not supported.
Uses rpyc for the connection backend (automatically installed).
1. Install the software dependencies:
|Python 2.7 (2.6 might work too):|
|gh-python-remote was developed with the Anaconda distribution in mind (comes with numpy and scipy included), but anything else works. If you already have Anaconda installed with Python 3, do not reinstall, instead just read the next paragraph.|
|Python virtual environment (optional):|
|isolate dependencies for each project by creating a new virtual environment. If you use Anaconda, conda env --name rhinoremote --python=2.7 will set you up with a new virtual environment named rhinoremote.|
|Rhinoceros3D:||version 5 is the only one supported by gh-python-remote, no other version works.|
|Grasshopper:||version 0.9.0076 is supported by gh-python-remote. Version 0.9.0061 and up might work as well. Open it at least once before continuing.|
|GH Python:||version 0.6.0.3 works best, older versions are buggy with gh-python-remote. Drop it on the Grasshopper canvas at least once before continuing.|
2. Install gh-python-remote:
From the Windows command line (or the special Anaconda or Python command if pip is not in your path by default), run: (If you are using a virtual environment, remember to activate it first.)
pip install gh-python-remote python -m ghpythonremote._configure_ironpython_installation
The first line installs gh-python-remote in the current Python interpreter. The second tries to find your Rhinoceros IronPython installation, and install gh-python-remote there.
If you do not use the standard Rhinoceros IronPython installation (%APPDATA%\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings), you can specify a target directory to use like so: python -m ghpythonremote._configure_ironpython_installation "location".
This will also install the gh-python-remote UserObject in Grasshopper.
All the examples files are copied in the %APPDATA%\Grasshopper\UserObjects\gh-python-remote\examples folder. You can also download them from the github repo.
From Grasshopper to Python
Open the example file GH_python_remote.ghx in Python, or drop the gh-python-remote component on the canvas.
Use the location input to define the location of the Python interpreter you want to connect to. You can use the path to a folder containing python, the full path to a python executable, or conda:// followed by the name of an Anaconda virtual environment.
Use the modules input to define the modules you want to access in the GHPython component. Anything that can follow an import statement in the remote Python works. If you need to import a submodule inside a package (like import this.that), the parent package has to be imported first.
Change run to True to connect.
In the GHPython component, the imported modules will be available via the sticky dictionary. For example if you are trying to use Numpy:
import scriptcontext np = scriptcontext.sticky['numpy']
* marks an input that is only available by editing the gh-python-remote UserObject, or in GH_python_remote.ghx.
From Python to Grasshopper
You can also use gh-python-remote to programmatically control a Rhinoceros instance, and connect to it via Python. Have a look at examples/python_to_GH.py for a full working example.
Licensed under the MIT license.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|gh_python_remote-1.0.4-py2-none-any.whl (91.9 kB) Copy SHA256 hash SHA256||Wheel||py2||Oct 6, 2017|
|gh-python-remote-1.0.4.tar.gz (85.6 kB) Copy SHA256 hash SHA256||Source||None||Oct 6, 2017|