Door and Window

From TOI-Pedia

Introduction

LEVEL: BEGINNER
Expected Time: 20 min
Possible result - a structured and ordered script

This tutorial will be different from previous tutorials that you may have done. In this tutorial we already created the scripts for you and you only have to download them! However, in this tutorial we will focus on some essential skills to structure your scripts to make them more readable. This is important, because you may want to reuse a script in the future, but that is only possible if you can figure out how it worked.

First, we will discuss the setup of the downloadable files. You can choose between a Door and a Window. The scripts work similar, but in the illustrations of this tutorial, we will use the window as example. After the setup, you will learn about grouping, wire display, structuring, ordering and commenting.

Result of the Door script


Result of the Window script


Remember to Credit the Author when using this script for your projects!

When you have downloaded the file, first open Rhino and start Grasshopper. Next, load the just downloaded file into Grasshopper.

  • Download one of the two files;
  • Unzip the Grasshopper file;
  • Start Rhino;
  • Open the unzipped downloaded file in Grasshopper.


Script setup

The input geometry of the window script

The Grasshopper script you just opened is based on multiple inputs:

  • A referenced Curve that defines the shape of the window/door;
  • A referenced Brep input that defines the shape of the wall;
  • Several Number Slider and color inputs

If you click on the parameters, you will see that the object highlights in the Rhino Viewport.

Without adding geometry, the parameter already has geometry internalized

You will now notice two important new aspects of the Grasshopper script. First, the parameters (Geometry, Curves etc.) in the script already have geometry. It is not necessary to set Rhino geometry before the script is usable. In Grasshopper, this is called internalised data. Internalised data has advantages and disadvantages:

Advantage:

  • When sending the script to someone else, you only have to send the Grasshopper file and not the Rhino file.
  • You can make sure the viewer uses specific geometry you want to use with the script.

Disadvantage:

  • Internalised data can make Grasshopper scripts much larger in file size.
  • It is not immediately clear which parameters contain internalised data.


Internalise Data

Internalizing data can be done with following method:

  • Set the geometry on a parameter RMB on parameter » Set one (paramtype) » Select Geometry in Rhino
  • Right click on the parameter and click "Internalise Data" RMB on parameter » Internalise Data


Displayed output, which is not selectable in Rhino

Furthermore, you will see that the result of the script is already visible in the Rhino viewport, although it cannot be selected. This means that the geometry of the script has not been "baked" yet.


Custom Preview

Grasshopper has a useful component called "Custom Preview" which can be used to make a preview render of the script output. By adding the "Material" component, you can select what color, transparency etc. you want to use for the geometry. If you want to change the data in Rhino, bake the "Custom Preview" node.

Structuring your Script

Grouping and Naming

Grouping multiple nodes

One of the main steps you need to take to structure your script is grouping. Select several nodes you think belong together and group them by right-clicking on the canvas and click on group. If you are not sure what nodes should be in a group, right-click on the node and click on preview on. The geometry outputted in this node is displayed in the Rhino Viewport.

  • Select multiple nodes Draw a rectangle around nodes by holding LMB
  • Group the nodes RMB on canvas » Group


Choose the colour of the group

Now you can give the group a color by right clicking on the group and select colour.

  • Select multiple nodes RMB on group » Colour » Select Colour


Name the group

You can also give the group a name by right clicking on the group and entering a name.

  • Select multiple nodes RMB on group » Enter name in top row from menu


Alternative naming: add a Scribble

As alternative you can also use the Scribble function. Double click on the canvas and write scribble. By double clicking on the text, you can change the name.

  • Add a scribble Params » Util » Scribble


Multiple groups in the script

Naming and grouping your script is important to make it understandable for other people. Furthermore, if you want to reuse your script in the future, it will be easier to find problems or make changes if you gave names to the groupes.

Align Modules

Align multiple selected nodes

Select multiple nodes and zoom in on the selection rectangle. You will see small icons that can be used to align your modules. It will be easier to read the script when it's getting larger. Give it a try!

  • Select multiple nodes Draw a rectangle around nodes by holding LMB
  • Click on the small icons near the selection rectangle


Wire Display

Change the wire display

Sometimes, your script has so much wires, that it becomes harder to read. By right-clicking on a node or node input, you can change the wire display to faint or hidden. However, always add an extra parameter in the beginning of a group to indicate an input if you make the wire display hidden.

  • Hide wires from the script RMB on node or node input » Wire Display » Hidden


Add a relay to a wire

If a wire is crossing other nodes, double click on the wire to add a relay. A relay does nothing to the script but makes it easier to follow the wires.

  • Add a relay Double click on wire


Structure Number Sliders

Add all Number Sliders to one group

In large scripts, it can be helpful to combine all Number Sliders and input into one small group. This makes it easier for other users to change the output of the script. Make sure you also rename them!

Comments

Explain the script in a comment

Sometimes it is difficult to understand a script at first glance. Add a panel to the script and explain what it does. Also explain the input parameters.

  • Explain your script with a comment in a panel Params » Input » Panel


Script Output

Add final geometry parameters

As always, add a geometry parameter at the end of the script to indicate the result. It can also be helpful to make a small group of all the results.

Further tips and tricks

For more information, take a look at Grasshopper "Good Practice".

Final result

The following downloadable files give an indication of how you could structure your script. In this case, no relays or Faint/Hidden wire types were used, because the script was deemed to small for that. Feel free to use the script in your project, but always remember to Credit the Author.

Personal tools
Actions
Navigation
Tools