Maski Grasshopper

How to use masks in grasshopper for data tree?!

90% of problems in Grasshopper come from the wrong manipulations of the data tree. Every week I get many questions regarding this topic and most of them can be easily solved with one component from the. I know it’s not that easy to choose the right component out of 26 components available. However, in this episode, I will present some of them. But first, let’s start with masks in Grasshopper which can be really helpful.

TIPS on how to use masks in Grasshopper.

1. Data tree structure

Let’s look into the tree structures. All of them are made out of tree branches and items. Items can also be called elements, indicates or leaves but let’s stick to one term – items. 

This example contains 3 branches and various numbers of items in them. In the first branch, we have 4 items, second has 3 and in the last one you can find 2. The mask helps with picking correct branches and items from the tree. It includes information about which number of branches and which item you would like to choose.

Data tree structure
Data tree structure in Grasshopper

On bimcorner blog, you can find the rules on how to build the masks. You can find the link in the description below.  I encourage you to print this picture and hang it over your desk. The following rules will work with the [Path Compare] , [Split Tree] and [Replace Paths] components.

Let’s go through this list with examples on how to use it. And the best tool for explanation will be the Split component. 

Split tree, Replace path, Patch compare
Grasshopper components which use masks

The split component is a very powerful tool in Grasshopper. This tree operation gives the ability to select a part of a tree or split into two. For that, you need to use string mask that specifies the positive output of your tree. In this example, I would like to pick the second branch and the second item in this branch. The result of this operation should be number six. Let’s look into positive output. On the panel, we can see that it just left one item and the rest are nulls. Elements which will not fulfil criteria will be left in output called the negative tree.

Split tree components
Original tree is preserved with using split tree

Mask in Grasshopper for just one element

Now I will show you the functionality of split trees on the grid of spheres. Data structure, in this case, will be 2 dimensional which means that the tree consists of one level of branches with items. If we would like to pick up just one element we can type just a path. In curly brackets, we can specify branches. Remember that each branch is supposed to be separated with a semicolon.

When a branch is specified we can go-to items. To specify items square brackets should be used. We need to remember that items are the last elements in data tree and the next levels of items can not be created. If we would like to extend our tree we need to add more branches with graft function for example.

Which Grasshopper Mask for more than one element?

Ok, but how to choose more than one element? I will explain that on a 3-dimensional tree. The base of this tree is from the previous grid and it was copied linear up. In this way, we got a second branch.

The asterisk allows you to pick any number of integers in a path. So for example, if we would like to choose all spheres from the first level of our tree we need to write in the path our constant value which is 0 and then insert an asterisk in the place for the second branch. Theoretically, we need to put an asterisk into the item mask (in square brackets) but actually, if we skip this part the program will choose all of them automatically.

You can also put a single asterisk between curly brackets, without semicolons. No matter how the path tree looks, it allows you to include all branches. And then you can choose some elements. In this case, all elements with item number 1 have been chosen.

asterisk in data tree
Asterisk in grasshopper masks

And more options...

Ok, we have curly brackets for branches, square for items, and what are standard brackets for? 

Standard brackets are used for organizing and grouping, mainly used with boolean and/or operators.

There are several ways how integers can be described in brackets. So, for example, putting a comma after every integer will pick only these integers. On the other hand, inserting between integers will pick up any integer in this range. It is good to know that the first and last integer in this range will be included as well. 

Moreover, if 3 dots will be inserted at the end, any integer of this infinite sequence will be selected. Sequences have to be at least two integers long and end with 3 dots after a comma. 

On the other hand, if you put 3 dots in the middle you will specify any integer which is part of this finite sequence.

Thanks to standard brackets it is also possible to combine two or more rules using the boolean and/or operators. The example selects all branches and the first 2 items in every list of a tree and also the items 5, 6 and 8.

Grasshopper mask - range
Range mask in Grasshopper

Now...

... advantages of using masks in Grasshopper

One of the biggest advantages of this tool is the fact that the original tree is preserved, and the elements that are split out are replaced with null. Therefore, when applying a transformation to the split tree, it is easy to recombine back. With other words, you can split your tree, make some modification on the splitted part, and afterwards join together without losing original data structure. 

and ...

... chellenges of using grasshopper masks

We need to remember that the created mask will work just for a specific number of branches. With every change of the data tree structure, we need to adjust the mask accordingly.

How to work faster in Grasshopper
List of masks in Grasshopper

What are your Grasshopper tips to work with complicated tree structures?

Write in the comments below what helps you to work with your colleges in Grasshopper?

Which components are you using for data tree manipulation?

Write an email at [email protected]

We always write back !!

Check out other articles from series Grasshopper Tips and Tricks:

For more informations about data tree manipulation download for free amazing book: Essential Algorithms and Data Structures – DOWNLOAD

Did you like that post ? Share it with others !

We spend a lot of time and effort creating all of our articles and guides. It would be great if you could take a moment to share this post !

Share:

Comments:

Subscribe
Notify of
guest
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments

Author:

Download BIM CASE STUDIES:

After reading this guide you will learn:

  • How BIM is used on the biggest projects in Norway
  • What were the challenges for the design team and how were they solved
  • What were the challenges on the construction site and what was our approach to them

Newest articles: