Grasshopper data types


Downloads material

🦗⬇️⬇️⬇️ Download the gh script file on curves here ⬇️⬇️⬇️🦗 🦗⬇️⬇️⬇️ Download the gh script file on surfaces here ⬇️⬇️⬇️🦗 🦗⬇️⬇️⬇️ Download the gh script file on parametric curves here ⬇️⬇️⬇️🦗 🦗⬇️⬇️⬇️ Download the gh script file on parametric surfaces here ⬇️⬇️⬇️🦗

Reference and bake geometries

The advantage of Grasshopper is that you can interact with objects drawn in Rhino so you don’t need to code everything from scratch. For example, you can draw two points in Rhino and create a line between those two points in Grasshopper. To do so:




Congratulations, you just created your first parametric line! Now, if you move the points in Rhino, the line will automatically be redrawn. However, you may have already realized that Grasshopper objects cannot be selected in the Rhino viewport. They are a bit like ghosts, you can see them but not interact with them… This is because to quickly regenerate new geometries and enable interactive feedback, Grasshopper only computes rough previews of the result. To interact in Rhino with a parametric object created in Grasshopper, you first need to bake that geometry. To do so, right-click on the “line” component and select “bake”.



To summarize:

Volatile and persistent data

Now imagine you would like to share your code that draws a parametric line with your colleagues. What would you do? One way would be to share both the .gh (or .ghx) and the .3dm files. However, this is not very practical as there is a risk that the two files might be later separated. A more robust practice is to only send the grasshopper file after internalizing the Rhino input into Grasshopper. To do so, right-click on the “point” components and select “internalize data”.



Now the link between the Rhino and Grasshopper objects is broken so moving the points in Rhino will no longer affect the position of the line. However, the previous location of the points is stored in Grasshopper so the line remains there. A data which is internalized in a Grasshopper component is said to be persistent as opposed to volatile data which is inherited from another source.

Volatile data can either be referenced to a Rhino object or transmitted from another Grasshopper component. Let’s expand our example by connecting the output of the “line” component to the input “C” of the “divide curve” component. This has the effect of dividing the line into ten pieces. The data arriving to the “divide curve” component is volatile as it is inherited from the “line” component. To make it persistent, we need to right-click on the input “C” and again select “internalise data”. This cuts the link between both components but stores the last line geometry in the input “C”.




Internalizing data is very useful to cut an algorithm into several steps or to save intermediary results in dedicated components. However, the more you internalize the data, the less parametric your codes are. It is up to you to find the good balance!

Primitive and geometric data types

The word data is a very broad concept that encompasses many different things. In computer programming, types are used to characterize similar groups of data. In the example above, we manipulated points and lines which are two data types that you can encounter in Grasshopper but there are many others. We can group the main data types present in grasshopper into two categories: Primitive and geometric data types. Primitive data types are common to many programs as they are directly built in the programming language used to code the software. Those include Booleans, Integers, Colors and Strings. On the contrary, geometric data types are only defined inside the Rhino environment and include Points, Vectors, Planes, Curves, Surfaces, Breps. You will find below a brief definition of the most common data types:

Primitive data types






Geometric data types











Type casting

When coding in Grasshopper (or other scripting environments), it is important to match the data types of the output and input of two consecutive components. To ensure you are passing the correct data type, you can hover any input or output of a component to display a more detailed description of the parameter. In the example below, we see that connected parameters always share the same data type (respectively curves, integers, and points).



However, in some particular cases, Grasshopper is smart enough to automatically convert data to the correct type. For example, if you pass a point to vector parameter, Grasshopper will create a vector with the same XYZ components than the points. The action of converting data from one type to another is called type casting (or type coercion). As points and vectors are both defined as a collection of three numbers, points can easily be casted to vectors and vice versa. In the image below, you can see other examples of type casting that are handled in Grasshopper, such as casting vectors to planes, or breps to meshes. While it is not possible to directly cast a point into a mesh, it is possible to achieve that result through successive casting operations.



Lastly, some data types can only be casted to other types under strict conditions. For example, a curve can only be casted to a surface if the curve is closed.