July 30, 2020

Gh & Py in Modeling: A brief for beginners

in some exclusive posts like this one, I am trying to have the path of how coding can change your way of looking through data-driven design, parametric modeling, and architecture, a little bit more indicated for beginners. As if you are familiar with the concept of why designers use coding in their processes, visual programming modules like Grasshopper3D provides a platform to define your algorithms by components as functions managing data and objects. The question that might come to mind is how these platforms work? What is the main structure behind and how an open API could be accessed by users like this with no programming background? There is a main core behind the scene while every component you call from the ribbon, refer to this core which includes a specific part of API. Python and other programming languages accessible in the canvas of Grasshopper can work like a hatch for us to have open access to RhinoAPI which is known as RhinoCommon.DLL. The same structure we can have by grasshopper components could be defined by a special python/C# component if you know the RhinoCommon as well as Grasshopper components. This process could get you acting more efficiently and having your definitions abstract well enough to take out your repetitive working procedures as your add-on. As a simple explanation, coding is like a key for designers to open up gates through different APIs whether it is Rhinocommon itself or other open-access ones

Sine cylinder algorithm

The algorithm presented as Sine cylinder example, take some parameters from the user and generate cylinders by Sine function while the generations are adapted fully connect from X, Y, and Z. the algorithm has been written by Grasshopper 3d components itself. The dotted marked component here also has been written by GHPython while every step is set just like the main algorithm above it. Just as you can check the whole double way scenario in the attached files to this post, each of these two ways is generating the same. The only difference in using python is implementing Rhinocommon directly while Grasshopper algorithm is working by its components. There are lots of beneficial aspects in using API but, the most challenging one is the ability to develop our tools according to our required situation and specific factors and parameters set/get impact to/from its environment and its users on design and its qualifications.

Pavilion mesh data manipulation

Although we can have our definitions more abstract, tangible, and high functional by coding, there might be other situations where we would need to code within the lack of specific functions we need besides the main components of Grasshopper. The file below contains a definition as a great instance for those who have to know how to use API within coding to solve specific issues. Here we had to mesh our output surface by parameters we might need. Using mesh class from API to give the user to be able to handle meshing data as to how the pavilion should have triangular panels according to surface curvature is the main problem. We tried to solve this by GHPython and just like 5 lines of codes.

Gh Definition!
You can download the file here and drag it to you Grasshopper canvas directly!
Architecture, Coding, Computational Design, OpenSource , , ,
5 1 vote
Article Rating
Notify of
Inline Feedbacks
View all comments