Is there a way to measure time since last execution of a python/C# script

I essentially wish to have a C# or python component that does the following

time_since_last_execution = time_now - time_when_this_component_was_last_executed
time_since_last_execution > 10s:

The “time_when_this_component_was_last_executed”-part is where I struggle

Hi @Timo_Harboe_Nielsen,

Use the dictionary that is on scriptcontext to store the last time value between executions.

import scriptcontext as sc
import time

def test_time():
    current_time = time.time()
    print(time.strftime("%H:%M:%S", time.gmtime(current_time)))

    if sc.sticky.has_key('last_time'):
        last_time = sc.sticky['last_time']
        elapsed_time = current_time - last_time
        print(time.strftime("%H:%M:%S", time.gmtime(elapsed_time)))

    sc.sticky['last_time'] = current_time


– Dale

1 Like

In GHPython one can also use the if “foo” not in globals(): method for making persistent variables. This example should get you going:

1 Like