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.



  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.


private void RunScript( int nx, int ny, 
  ref object Geometry, ref object AnnoTxts, ref object AnnoPnts )
  //-- SOP IN
  geometry = new List<object>( );
  annotxts = new List<string>( );
  annopnts = new List<Point3d>( );

  //-- Printing a structured Message
  Print("{0}", "hi there");

  //-- Annotating a 3D point with a message
  Log(new Point3d(0, 1, 2), "Hello There");

  //-- Adding geometry to visual buffer
  geometry.Add(new Line(new Point3d(0, 0, 0), new Point3d(5, 5, 5)));

  //-- SOP OUT
  Geometry = geometry;
  AnnoPnts = annopnts;
  AnnoTxts = annotxts;

// <Custom additional code> 

public List<object> geometry;
public List<string> annotxts;
public List<Point3d> annopnts;

public void Log(Point3d point, string message)

// </Custom additional code> 


  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.