1st March 2024

GHEC 03 : Handling Grasshopper Data

Today's focus

  • Understanding Data Types: The What and Why
  • How Rhino and Grasshopper Share Data

Understanding Data Types: The What and Why

Grasshopper, like any other program, sends commands to your computer in binary (1s and 0s). That means it can't differentiate the text version of "1" and the number version of 1 without additional instructions. So, we as Grasshopper users, need to tell the computer the type of data it's dealing with.

This is so that the computer can process the data as we intended it to. When we give a "1" to the computer, we have the option of specifying whether the "1" is a number or text. Depending on what you are doing, the computer can process the data very differently.

For this reason alone, we need to know all the data types that Grasshopper has to offer. Mostly so that we can be accurate in telling the computer what to do.

The Two Main Categories of Data Types

In Grasshopper, there are two categories of data types, Geometry and Primitives.

Pasted image 20240122113449.png

Note: Plugins can also add more categories of data types

Geometry Datatypes

Things like points, curves, surfaces, and more are geometric data types. These data types are pretty intuitive to use. E.g. A point is made of coordinates, a line is made from two points, etc.

What gets tricky is that Grasshopper lets you convert between some of these types even when you don't mean to. Let's see what happens when I just plug a point into a plane component.

point To Plane.gif

This is a good thing and a bad thing. It's good because this makes it super easy to define a plane. it's bad because it's not obvious a data type conversion has happened. Not to mention, it cost extra resources to convert that point to a plane. It doesn't affect your script for one point but imagine converting 100,000 points.

You can even do this data type conversion for more complicated types. Like converting convert a curve to a plane or a surface.


I hope you can start to see how dangerous this can be. Grasshopper makes it very easy to convert between data types but that also means it's easy to screw up the data you are working with.

Converting a point to a plane makes sense but a curve to a plane? The plane from that conversion can be random and unpredictable.

That being said, not all data types are convertible. When you try to convert a data type into something that Grasshopper doesn't support, it will throw an error.

rect to line.gif

So, because of this flexibility in converting data types, you need to be intentional with the type of data that you are using.

Catch-all Geometric Data Types

There are also "catch-all" data types that allow you to hold any kind of geometric data without converting them. Take the curve data type for example, you can pass in a line, circle, rectangle, and more and it will still retain it's original type.

Pasted image 20240206101019.png

You can even take it a step further and use the geometry data type which accepts any type of geometric data.

Pasted image 20240206101729.png

Primitive Datatypes

Primitive data types are what we refer to as "raw" data. Simply put, they don't produce any visual output in Rhino. These are types like text, numbers, domains, etc.

They are also quite intuitive to use and similar to geometric data types, Grasshopper lets you easily convert between these types. Particularly between text and other primitive data types.

Pasted image 20240122114949.png

But unlike geometric data types, converting between primitive data types is less random and more predictable. But I still do recommend to keep conversions to a minimum unless it's intentional.

Converting text to other types

In previous sessions, we have seen how we can enter text in panels and if we follow a certain convention, Grasshopper can convert it into another data type. Like how "0 To 10" can be turned into a domain.

Here are all the conventions that you can use in text to convert into another data type.

Pasted image 20240122115513.png

These are useful to know because it's sometimes faster to use a panel than to use their respective construct components. It can also be easier to understand, especially if they are inputs to a script.

Catch-all Data Types

Similar to geometric types, there are also primitive catch-all types. I would technically call the text component a catch-all type since it handles most types.

Pasted image 20240206102019.png

But the true catch-all type is the data component because it accepts any data type. You can pass in both geometric and primitive types or even your own custom-defined ones.

Pasted image 20240206102245.png

It's like the geometry component but on steroids.

Thoughts on Conversion

It's important to be intentional with data type conversions because doing them wrong can significantly impact your script's performance. Here's a screenshot from a script from when I accidentally plugged a text from a point.

Notice how much longer it takes to convert to text

How Rhino and Grasshopper Share Data

Now that we know the types of data Grasshopper has, it's time to talk about how that data is share with Rhino. I mentioned in our first session that Rhino is just Grasshopper's data visualizer and storage, while that is true, it isn't the whole truth. It's time we dive deeper.

For the most part, Grasshopper uses the same data definition as Rhino. It's about to get complicated so bear with me.

Even though Grasshopper and rhino share the same definition, they don't share the data. This means what makes up a point in Rhino is the same as in Grasshopper.

But making a point in Grasshopper doesn't automatically place that point in Rhino.

Simply put, Grasshopper handles the process, while Rhino stores and showcases only the results. So, even if we drew a line in Rhino, the program only stores the line not how the line was made.

To understand how Grasshopper and Rhino share data, there are two concepts that we must understand: Referencing and Baking.

Referencing geometry in Grasshopper

To "bring in" Rhino geometry into our Grasshopper scripts, we have to reference the geometry in Rhino.

Referencing builds a link from Rhino's geometry to Grasshopper, it doesn't mean the Rhino geometry is now in Grasshopper. This is important to know because if you delete the geometry in Rhino, it will disappear from Grasshopper too.

Let's see how to reference geometry From Rhino to Grasshopper.

Rhino Reference Point.gif

You can reference geometry from any geometry input of a component. When you right-click on the input, you should see an option to "set a geometry" or "set multiple geometry".

Pasted image 20240119100259.png

It's always best practice to only reference Rhino geometry on containers just so it's clear on the script that it's an input.

Note: A good indication that a link has been set, is when the geometry turns red/green in Rhino

Baking geometry/data to Rhino

On the flip side of this, we can send geometry from Grasshopper to Rhino through baking. Similar to how you reference geometry, you can bake geometry by right-clicking on any component output and choosing bake.

Baking a circle.gif

The main difference between baking and referencing is that baking is permanent. As in, when you bake geometry into Rhino, you are sending geometry for Rhino to store not link.

You can see this by baking some geometry and then deleting the Grasshopper components. You'll see that the geometry won't change in Rhino.

That means that if you modify the Grasshopper script, you have to delete what's in Rhino and re-bake the geometry again.

Note: Don't worry there are free Grasshopper plugins out there that can streamline this process.

Today's Homework

To understand referencing and baking, I think all you need is some practice. For this task, I am going to give you a Grasshopper script and I want you to reference rhino geometry into the script for it to work. Then, once the script has ran, I want you to bake the output into Rhino.

I have left notes on what type of geometry to reference and what layer to bake the geometry to.

Here is the link to the file: ​Session 03: Baking and Referencing​

Final Thoughts

Even though we learnt about two things today, data types and data sharing. I found it difficult to create a task around data types. I often see that being intentional with your data types is performance based and can only be showcased with a really large script.

But as you start scripting more, it pays to ingrain these good habits from the beginning.