{"id":14989217,"url":"https://github.com/pilcru/ghpythonremote","last_synced_at":"2025-08-22T06:32:47.457Z","repository":{"id":57323751,"uuid":"89932239","full_name":"pilcru/ghpythonremote","owner":"pilcru","description":"A two-way connector to use regular Python from IronPython in Rhino/Grasshopper, and vice-versa.","archived":false,"fork":false,"pushed_at":"2022-11-21T14:30:34.000Z","size":5549,"stargazers_count":124,"open_issues_count":9,"forks_count":35,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-12-09T06:32:32.222Z","etag":null,"topics":["grasshopper","grasshopper3d","ironpython","matlplotlib","numpy","python","rhino","rhino3d","rhinoceros","scipy"],"latest_commit_sha":null,"homepage":"https://github.com/pilcru/ghpythonremote","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pilcru.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-01T14:43:33.000Z","updated_at":"2024-11-12T19:51:10.000Z","dependencies_parsed_at":"2023-01-23T11:45:14.105Z","dependency_job_id":null,"html_url":"https://github.com/pilcru/ghpythonremote","commit_stats":null,"previous_names":["digital-structures/ghpythonremote"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilcru%2Fghpythonremote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilcru%2Fghpythonremote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilcru%2Fghpythonremote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilcru%2Fghpythonremote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pilcru","download_url":"https://codeload.github.com/pilcru/ghpythonremote/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230568590,"owners_count":18246378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grasshopper","grasshopper3d","ironpython","matlplotlib","numpy","python","rhino","rhino3d","rhinoceros","scipy"],"created_at":"2024-09-24T14:17:53.155Z","updated_at":"2024-12-20T10:08:29.785Z","avatar_url":"https://github.com/pilcru.png","language":"Python","readme":"================\ngh-python-remote\n================\n\n| Connect an external python instance to Grasshopper, and vice-versa.\n| This lets you run any Python package directly from Grasshopper, including numpy and scipy!\n\n.. image:: https://raw.githubusercontent.com/Digital-Structures/ghpythonremote/9d6773fbc0cc31cc042b5622aadd607716e952f7/GH_python_remote_plt.png\n   :width: 900px\n   :align: center\n\n====\n\n************\nInstallation\n************\n\nRequires a Python 2.7 installation, not compatible with Python 3. Compatible with Mac and Windows with Rhino 7.\n\n1. Install the software dependencies:\n-------------------------------------\n\nBefore installing gh-python-remote in **Rhino 7**, you will need to install Python 2, Rhino 7, and open Grasshopper in Rhino 7 at least once.\n\nBefore installing gh-python-remote in **Rhino 6**, you will need to install Python 2, Rhino 6, and open Grasshopper in Rhino 6 at least once.\n\nBefore installing gh-python-remote in **Rhino 5**, you will need to install Python 2, Rhino 5, Grasshopper and GHPython, and drop the GHPython component on the Grasshopper canvas in Rhino 5 at least once.\n\nInstall the following:\n\n:Python 2.7:\n    gh-python-remote was developed with the `Anaconda`_ and `Miniconda`_ distributions in mind, but any Python 2.7 distribution works. If you already have Anaconda installed with Python 3, you do not need to reinstall it, you can create a virtual environment as explained below.\n\n    *If you want to be able to name virtual environments in gh-python-remote by their conda name, select \"Add conda to my PATH\" when prompted during Anaconda's installation.*\n\n    *On Mac, the python distributed with the OS is outdated and difficult to use by the end-user. It is* **highly** *recommended to use a conda- or* `brew`_ *-based Python.*\n:Python `virtual environment`_ (optional):\n    Isolate dependencies for each project by creating a new virtual environment. If you use Anaconda or Miniconda, creating a virtual environment is easy.\n\n    - Open the Windows command prompt, or Mac terminal (or the Anaconda prompt if you chose not to add conda to your PATH during insallation)\n    - Run the following command:\n\n    .. code-block:: bash\n\n       conda create --name rhinoremote python=2.7 numpy scipy\n\n    This will create a new virtual environment named ``rhinoremote``, and install numpy and scipy in it.\n:`Rhinoceros3D`_:\n    Version 7 is supported on Windows and Mac. Version 5 and 6 on Windows should work, but are not supported.\n:`Grasshopper`_:\n    On Rhino 6 and 7, it is already installed. On Rhino 5, install version 0.9.0076. **Open it at least once before continuing.**\n:`GH Python`_:\n    On Rhino 6 and 7, it is already installed. On Rhino 5, install version 0.6.0.3. **On Rhino 5, drop it on the Grasshopper canvas at least once before continuing.**\n\n2. Install gh-python-remote:\n--------------------------------\n\nFrom the Windows command prompt, or Mac terminal (or the special Anaconda, or Python prompt if pip is not in your path by default), run:\n\n*(If you are using a virtual environment, remember to* **activate** *it first. With the conda virtual environment from above, you would need to run* ``conda activate rhinoremote`` *in the command prompt.)*\n\n.. code-block:: bash\n\n   pip install gh-python-remote --upgrade\n   python -m ghpythonremote._configure_ironpython_installation\n\nThis will install gh-python-remote for Rhino 7, and install the gh-python-remote UserObject in all Grasshopper versions.\n\nThe ``ghpythonremote._configure_ironpython_installation`` script takes an optional location argument that can be ``5``, ``6``, ``7`` (default), or the path to a target IronPython package directory.\n\nFor example, to install for Rhino 5, replace the second command with:\n\n.. code-block:: bash\n\n   python -m ghpythonremote._configure_ironpython_installation 5\n\nTo install to another location:\n\n.. code-block:: bash\n\n   python -m ghpythonremote._configure_ironpython_installation ^\n     \"%APPDATA%\\McNeel\\Rhinoceros\\7.0\\Plug-ins\\^\n     IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\\settings\\lib\"\n\n====\n\n*****\nUsage\n*****\n\n*All the examples files are copied to* ``%APPDATA%\\Grasshopper\\UserObjects\\gh-python-remote\\examples`` *on Windows, and* ``~/Grasshopper/UserObjects/gh-python-remote/examples`` *on Mac. You can also download them from the* `github repo`_.\n\nFrom Grasshopper to Python\n--------------------------\n\nStep-by-step\n^^^^^^^^^^^^\n\n#. Open the example file ``GH_python_remote.ghx`` in Grasshopper, or drop the gh-python-remote component on the canvas.\n#. Use the ``location`` input to define the location of the Python interpreter you want to connect to.\n#. Use the ``modules`` input to define the modules you want to access in the GHPython component.\n#. Change ``run`` to ``True`` to connect.\n#. In the GHPython component, the imported modules will now be available via the sticky dictionary. For example if you are trying to use Numpy:\n\n   .. code-block:: python\n\n      import scriptcontext\n      np = scriptcontext.sticky['numpy']\n\nNotes\n^^^^^\n\nCreating remote array-like objects from large local lists is slow. For example, ``np.array(range(10000))`` takes more than 10 seconds. To solve this, you need to first send the list to the remote interpreter, then create the array from this remote object:\n\n.. code-block:: python\n\n  import scriptcontext as sc\n  import ghpythonremote\n  np = sc.sticky['numpy']\n  rpy = sc.sticky['rpy']\n\n  r_range = ghpythonremote.deliver(rpy, range(10000))\n  np.array(r_range)\n\nAdditionally, Grasshopper does not recognize remote list objects as lists. They need to be recovered to the local interpreter first:\n\n.. code-block:: python\n\n  import scriptcontext as sc\n  import ghpythonremote\n  from ghpythonlib.treehelpers import list_to_tree  # Rhino 6 only!\n  np = sc.sticky['numpy']\n\n  a = np.arange(15).reshape((3,5))\n  a = ghpythonremote.obtain(a.tolist())\n  a = list_to_tree(a, source=[0,0])\n\n\n``ghpythonlib.treehelpers`` is Rhino 6 only, see the `treehelpers gist`_ for an equivalent implementation if you need it on Rhino 5.\n\nQuick-ref:\n^^^^^^^^^^\n\n**\\*** *marks an input that is only available by editing the gh-python-remote UserObject, or in* ``GH_python_remote.ghx``.\n\n:Arguments:\n    :\\*code (string):\n        Path to the ``GH_to_python.py`` code file.\n    :location (string):\n        Path to a python executable, or to a folder containing ``python.exe``, or the name of a conda-created virtual environment prefixed by ``conda://`` (``conda://env_name``, requires ``conda`` available in your PATH). If empty, finds python from your windows ``%PATH%``.\n    :run (boolean):\n        Creates the connection, and imports new modules, when turned to True. Kills the connection, and deletes the references to the imports, when turned to False.\n    :modules (string list):\n        List of module names to import in the remote python. They will be added to the ``scriptcontext.sticky`` dictionary, allowing them to be reused from other python components in the same Grasshopper document. Submodules (for example ``numpy.linalg``) have to be added explicitly to this list to be available later, and importing the parent package is also required even if only the submodule is used.\n    :\\*log_level (string from ['NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']):\n        Logging level to use for the local IronPython and the remote python instance.\n    :\\*working_dir (string):\n        Working directory for the remote python instance.\n\n:Returns:\n    :out (string):\n        Console output with DEBUG information.\n    :linked_modules (string list):\n        List of imported module names.\n    :rpy (rpyc connection object):\n        The object representing the remote Python interpreter.\n    :import_statements (string):\n        What to use in the GHPython component to actually use the imported modules.\n\n\nFrom Python to Grasshopper\n--------------------------\n\nYou 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.\n\n====\n\n*******\nLicense\n*******\n\nLicensed under the `MIT license`_.\n\n.. _Anaconda: https://www.anaconda.com/download/\n.. _Miniconda: https://docs.conda.io/en/latest/miniconda.html\n.. _brew: https://docs.brew.sh/Homebrew-and-Python\n.. _virtual environment: https://docs.python.org/3/tutorial/venv.html\n.. _Rhinoceros3D: https://www.rhino3d.com/download\n.. _Grasshopper: https://www.rhino3d.com/download/grasshopper/1.0/wip/rc\n.. _GH Python: http://www.food4rhino.com/app/ghpython#downloads_list\n.. _github repo: https://github.com/Digital-Structures/ghpythonremote/tree/master/ghpythonremote/examples\n.. _treehelpers gist: https://gist.github.com/piac/ef91ac83cb5ee92a1294\n.. _MIT License: https://github.com/Digital-Structures/ghpythonremote/blob/master/LICENSE.txt\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilcru%2Fghpythonremote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpilcru%2Fghpythonremote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilcru%2Fghpythonremote/lists"}