A simple timer example for the Grasshopper C# component


Create a simple timer in Grasshopper using the built-in C# component with this example script.

What this does

Set runtimer to true. The component will build a list of the current time and date, once per second.

When runtimer is set to false, the timer is turned off and the list is displayed.


  private void RunScript(bool runtimer, bool reset, ref object A)
    if(runtimer) Example.TurnOnTimer();
    if(!runtimer) Example.TurnOffTimer();
    A = rtnlist;

  // <Custom additional code> 

  public static List<string> rtnlist = new List<string>();

  public class Example
    public static System.Timers.Timer aTimer = new System.Timers.Timer(1000);

    public static void TurnOnTimer()
      aTimer.Elapsed += OnTimedEvent;
      aTimer.Enabled = true;

    public static void TurnOffTimer()
      aTimer.Elapsed -= OnTimedEvent;
      aTimer.Enabled = false;

    private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)


You can download the above code as a Grasshopper user object here

Further information

MSDN guide: timers in C#

Grasshopper timer using Python

If you are looking to add a timer to a Python component without using the timer component, have a look at Anders Deleuran’s code here.

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.