July 30, 2020

Using other APIs with Gh: Anacodna

The most amazing part of coding and what benefits are to have the chance of connecting different APIs within RhinoCommon. This is just in case where you know RhinoCommon well enough to bring other ones in action too. As an example, I need to have an energy calculator engine or daylight simulation part in the middle of my algorithm to check if my design works well or not! Lots of similar ideas could be found if you search for it in Food for Rhino but they all are different by process speed, parameters included and other dependencies which you might not need or even you want to have them customized. This is a great experience to have if you can choose a package or an opensource library and link it to your algorithm by coding from RhinoCommon to the other one. There are rules and restrictions we will talk about of course but the possibility we are talking about couldn’t be accessible if McNeel and Associates had nothing open access. Thanks to them, we are now observing other huge companies opening up their API partially which let us do whatever we require. Just think about having a world of opensource applications where we can develop innovative ideas and create child apps by combining APIs.

Let’s rehearse what has been mentioned as an example where I tried working on Anaconda as one of the most enterprise platforms for using other APIs in the project: “Generative design: Iranian Girih Geometry based free form structures”. Since I have started to work on AI and Machine Learning Algorithms, I couldn’t find a superior one comparing to Anaconda. The question that comes up here to mind is: What is Anaconda? How it’s been defined on Anaconda official website:

The open-source Anaconda Individual Edition (formally Anaconda Distribution) is the easiest way to perform Python/R data science and machine learning on Linux, Windows, and Mac OS X. With over 19 million users worldwide, it is the industry standard for developing, testing, and training on a single machine, enabling individual data scientists to:

GHPythonRemote and Anaconda Connectivity

In the earlier of this post, I pointed out about restrictions to use APIs. One of the biggest challenges we face while loading other APIs within Python in Rhino and Grasshopper is, we have to reconsider that the main context we are coding in is IronPython which has its terms of use. As an instance, it cannot load Python’s most commonly used packages in data science. Before heading to the subject of the issue I have to explain what these packages are and why we need them. Data science is being comprehensively viral since AI and Machine Learning Algorithms’ main initial and necessary sustenance is data. There are lots of packages you can search for different data types, a high mathematical procedure diversity, and get/set data from one platform to another in different dimensions. Here what we need to turn over the lack of coverage by IronPython is something that links GHPython to what Anaconda defines as a virtual machine called environment. Instead of having a machine with specific packages, Anaconda creates a virtual one for each project we have by required packages on one machine. This is the first step we will discuss later to know how the process goes. Before anything goes to define an environment, using GHPythonRemote is the first key to open the door of having other APIs and packages within IronPython. It works as an add-on written by Digital Structures at MIT dedicated to Pierre Cuvilliers. It’s an opensource project accessible on GitHub. According to the project definition:

GH Python Remote is a special set of tools in Grasshopper that lets you use regular Python code directly in the GHPython component. This means you can use NumPy, SciPy, Matlplotlib, et al. right inside of Grasshopper.

As a practical example, I defined one of the training projects I teach in learning how to code in Python within Grasshopper, by using GHPythonRemote. We will discuss it in another post and you can find it on my blog. As mentioned above the project Generative design: Iranian Girih Geometry based free form structures using Numpy, Pillow, Matplotlib, and OpenCV. It is undergoing and I will share every step of any progression. The procedure of running GHPythonRemote and using Anaconda to have packages we had needed to be explained below similarly to what has been presented on

1. Python and Environment Setting up:

  1.1. Creating Env: “conda create –name rhinoremote python=2.7 numpy scipy

  1.2. Rh 5 & Rh 6 + Gh 0.9.0076 & Gh 1.0.0007 are supported

  1.3. Run GHPython Once before

  1.4. Different Environment by Anaconda for each project

2. Install gh-python-remote:

  2.*. Checking Env List: “conda env list

  2.1. Activate Environment (“activate rhinoremote”) by Anaconda prompt

  2.2. Run “pip install gh-python-remote –upgrade

  2.3. Run “python -m GHPythonremote._configure_ironpython_installation

  2.4. in case for Rh7 or Rh5, Run:

         python -m GHPythonremote._configure_ironpython_installation 5

3. Installing packages:

  3.1. Checking what packages have been installed: “conda list

  3.2. Installing Pillow, OpenCV, MatplotLib: “conda install pillow” et al.

Architecture, Coding, Computational Design, Data Science & Visualization, Favorites & More, Lectures and Presentations, Machine Learning, OpenSource , ,
5 1 vote
Article Rating
Notify of
Inline Feedbacks
View all comments