Standard Operating Procedure for Grasshopper Coding

The objective of this tutorial is to establish a template for coding using C# in Grasshopper. The component will set up some standard output containers for information visualized in the 3D viewports as well as in text form inside Grasshopper. The format I am using establishes some good principles for rapid experimentation.

Template

Technique

  1. Create a standard C# component and place it in the document.
  2. Rename the outputs to Messages, Geometry, AnnoTxts and AnnoPnts following exactly the capitalization seen above. The inputs will vary so we can ignore them for now.
  3. Append a text panel and 3D annotation display component connected as seen above.
  4. Open the code editor and include the following boilerplate code as seen below.

Procedure

Remarks

  1. The outputs are reflected by internal variables which are stored in class level scope so they are accessible from every part of the code (not only from inside the main script procedure).
  2. The Logging function is helping with ensuring that for every annotation message we also collect an annotation point. It is shortcut function.
  3. The geometry collection is type as object to signify that we will dump varied types of information and let grasshopper figure out which are visual etc.
  4. The Print function contained in every grasshopper script allows you to format and print text messages in a panel.
  5. The naming convention we will be using is as follows: all incoming information from the grasshopper UI will be passed as Capitalized variables/parameters into our code. Internally we will only use lower case variable names as a way of visually keeping clean what is internal and what is external.