Visual programming 1
Introduction to Grasshopper
Last updated
Introduction to Grasshopper
Last updated
The objective of this session is to introduce Grasshopper. The contents of this session are purely technical introducing the user interface and basic mechanics of constructing graphs to express computational logic. This introduction is kept brief so that we can jump straight into hands-on programming exercises in this programming environment.
Grasshopper is a Visual Programming Environment that is part of the Rhinoceros 3D modelling software. Type the command Grasshopper to open the environment in a separate window.
A – Main Menu Bar is where you can access several drop-down menus: File (opening/saving files etc.), Edit (operations like cut and paste), View (adjust Grasshopper view such as panels), Displays (adjust how canvas is drawn and geometry is previewed) and Help
B – File Browser control allows you quickly switch between currently open Grasshopper definitions
C – Toolbar Panels contains components organised by categories. Click on the little arrow to expand the panel and view all components in that category.
D – Window Title bar firstly shows the name of the current Grasshopper definition. Secondly, double-clicking it allows you to fold/unfold the window frame.
E – Canvas is the editor where you construct/edit the graph of nodes (components/parameters) and edges (wires).
F – Rhinoceros viewport displays a preview of any geometry that is generated by Grasshopper
In visual programming we represent computation logic by constructing comprised of nodes and edges. In this particular visual programming application, nodes are called “components” and edges are called “wires”. Nodes express one or more data operations packaged in a . They require a number of inputs parameters, perform a transformation, and emit a number of parameters as outputs. Components always list and accept inputs on the left hand side and emit outputs on the right hand side.
The term “black-box” is used because we do not necessarily know, or need to worry about, how a component performs its functions. The idea of inhibiting knowledge of a component’s internals has nothing to do with secrecy. Instead it may be considered as an approach for capturing functionality and compartmentalizing knowledge. This is beneficial because we can reduce complexity and improve re-usability.
There are two display settings for components controlling visual verbosity. Using the “draw full names” toggles between complete and reduced versions of the input, label and output descriptions. Using the “draw icons” display option toggles between text and icon styled components. Using full names is generally useful for sharing graphs via pictures as component logic is more legible.
We may also freely rename inputs, outputs and even components’ labels to annotate them with semantically more memorable names. Generally this is not recommended when sharing graphs because the components may become ambiguous. Instead we may use the groups and annotate them as seen below.
Grouping allows us to organize logic regions as well as adding some minimal amount of documentation as per the intent of the computation; both recommended practices for developing complex graphs.
Some operations cause computing errors such as for example division by zero. This is visually denoted by components turning red; a pop-up annotation icon appears at their corner with additional information; and the output value returned is “<null>”.
Components are linked together via wire conduits. Wires express the data flow from one component to another; they just capture relationships visually. Data flows always from the output of one components to the input of another. We link components by dragging wires from their output handles to the input handles of others.
We can disconnect already linked components using the context menu situated right above an input parameter. Note that each component may have its own extra menu items in their context menu. The disconnect operation is so fundamental that all of the component support it.
Wires can be also styled using the “wire display” options in the context menu again situated right above them. Most often we use the “default” style but we may also reduce wire visibility using the “faint” option or completely hide them by using the “hidden” option.
The only constraint regarding wires is that we cannot form circuits by chaining one or more components into a closed loop. This represents an infinite computation i.e. lock down or crash. Thus the graphs we can create using this environment look more like hierarchies, tree-like structures or more formally directed acyclic .
The canvas where you construct the graph is 2D and supports only pan and zoom functionality via the left and right mouse button respectively.
From the canvas’s tool strip (upper right) we often use the display buttons to switch between: completely hiding all geometry generated by the graph, display of only wireframes and display of wireframes and surface shading.
Feel free to experiment and learn what the other viewport’s tool strip button do. As they are not very frequently used, exploring them is left for the curious.
The representation of wires conveys further semantic meaning. Wires are displayed as single lines, double lines or dashed lines. Make sure you enable Display Fancy Wires (under Display menu) option first though. A single line wire implies that it is transmitting a single data item. Double lines imply that the data is a list of items. Finally dashed lines mean that the data is structured in the form of a .