Grasshopper Tutorials Part 2.3

This is a grasshopper definition of a facade system with louvers that change direction based on the location of a point. One objective of this tutorial is to introduce the use of scripting components.

Placeholder and reactive patterns

Placeholder and reactive patterns

This definition is a combination of the 'Placeholder II' and 'Reactor' patterns. In this example the louvers orient themselves towards the reference point (only in XY plane). We create vectors from each louver line's mid point towards the reference point. We then extrude these lines using the created vectors (with the z adjusted to 0). The structure for the definition is therefore very similar to 'Placeholder II' where we ensure that inputs (input choices 1 and 2) are similar (a collection of 4 points).

Definition overview

Definition overview

A scripting component is introduced into the definition (this is documented in the video part 2). The scripting component encapsulates a simple logic that states "If the louver is higher (z information), then increase its extrusion depth". This simple logic can be modeled using normal grasshopper components, but the intention here is to  demonstrate how a scripting component is set up and then how the code is written.
Setting data type

Setting data type

The scripting components can be found under the Math > Script tab. Grasshopper allows either C# or VB.Net languages - we use VB.net in this example as its syntax is closer to normal English and therefore more readable for users unfamiliar with coding languages. In either case, the language differs from VB script (used in rhinoscript) as both C# and VB.net are object oriented languages. The learning curve for using an object oriented programming language is steeper, but the payoff is that you can accomplish more with it e.g. create and use custom classes.

Double clicking the component opens the script editor, which allows you to write code. For users unfamiliar to code, a helpful first step is to figure out what you want the component to return (or output) then write out the steps to get there. In this case I need my component to give me a vector to feed into my final 'Extrusion' component. In this example, the pseudo-code is as follows: i) get the start point of the louver line, ii) get the z height of this start point, iii) get an extrusion distance which is given by extrusion factor (which is an input from my slider) multiplied by the z-height of the point, iv) create a new vector based on the reference vector (an input) and v) multiply its x and y values by the extrusion distance from (iii) but make its z-value 0, and finally output this vector. Once the pseudo-code has been written, the next step is to translate it from plain english to the coding language. This is usually the major stumbling block for beginners who find programming syntax cryptic and idiosyncratic. But with practice and familiarity, the process of writing code will get easier.

VB scripting component

VB scripting component

Some more examples of scripting components can be found here in one of our earlier posts. Note that these scripting components were written for Grasshopper version 6 and based on older .NET SDK and thus the object types in the code are a little outdated. As a final touch to the facade, the 'coloring' definition in 'Reactor 3' pattern is added. Instead of creating a definition that does everything, a good strategy in Grasshopper modeling is to create definitions that accomplish a well defined  single task (a pattern), and then combine them later on to create a more sophisticated model!

Facade with gradient

Facade with gradient

The grasshopper definition can be downloaded here.

/