Using python to do a counter in dynamo

Hi, everyone
I want to do a counter which i can custom period for example , 10ms , 100ms or 1000ms.

i wrote a short script, it can not run as a counter, always show 1.

Thanks in advance.

1 Like

@yangshilun2012 ,

i search also for that… something similar, intressting part is also how to stop this process…!

#Created By Brendan Cassidy

import clr

#Imports date/time info
from time import gmtime, strftime
#Applying time Day-Month-Year at Hour:min
time_info1=strftime("%d %b %Y at %H:%M", gmtime())

#     OR

from System import DateTime

OUT = time_info2

Try the sleep() method from the time library (import time). If your code is all running in Python, you can integrate the waits into your overall outcome, then loop it in the python block n number of times instead of running once.

Hi, GavinCrump Thanks, I am a beginner of dynamo python. would you like to write down the script?

I am a new user, so I am not sure this python script is as same as DateTime.Now Node in dynamo. Anyhow using DateTime.Now Node, then switch dynamo to Periodic Mode can make it run. In this way I only can get a second counter, right?

@yangshilun2012 ,


i wanted to manage a task here via an intervall of time

because the node and the variables are re-initialized at each instance/launch
some solutions:

  • save the variable outside the script (txt file, pickle, …)
  • use a node to get/set the variable (see this example)

thanks, it works. I use node as input, switch to periodic mode, but it is stuck in 10ms, only works fluently in 100ms 1000ms, probably there will be a better way.

1 Like