# A counter for number of Runs

**URL:** <https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090>\
**Category:** Uncategorized\
**Tags:** dynamo\
**Created:** [July 24, 2018, 5:42pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090 "2018-07-24T17:42:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 24, 2018, 5:42pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/1 "2018-07-24T17:42:57Z")

</div>

I updated my dynamo to 2.0.1 (from 1.3.1 version). The part that is considered as “second counter” does not work now. In other words, it does not count and the “tCount” is given “null” value at every run. It seems it cannot store values from previous runs anymore.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/4/14016875f0fbcc1087b6eaa11230bf09f077a951.png)

So, If you run it in Dynamo 1.3.1 the highlighted “Watch” node shows the number of runs, but in 2.0.1 version it does not count and it shows 0.

- I attached the code here. If you want to test, make sure to have two copy of the code; one for 1.3.1 and one for 2.0.1. (since when the code is updated to a newer version, it cannot be opened by previous ones)  
[second counter.dyn](https://forum.dynamobim.com/uploads/short-url/jLfwHMeYJNUIgqkP3OZ288y57N6.dyn) (3.3 KB)

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [July 25, 2018, 2:38pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/2 "2018-07-25T14:38:31Z")

</div>

I think this is related:

> <https://github.com/DynamoDS/Dynamo/issues/8977>

try the suggested workaround at the bottom of the thread please.

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 25, 2018, 5:10pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/3 "2018-07-25T17:10:54Z")

</div>

Hi Michael,  
It is not the solution to my problem. But, thanks for your consideration.

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [July 25, 2018, 6:20pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/4 "2018-07-25T18:20:17Z")

</div>

FYI @Aparajit_Pratap

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [July 26, 2018, 7:04am UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/5 "2018-07-26T07:04:22Z")

</div>

Note that your variable is defined outside of the imperative scope. In Dynamo 2.0, you can no longer redefine variables in the same code block in associative mode.

---

<div class="post-metadata">

**Author:** ![adam\_bear1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/adam_bear1/32/13411_2.png) [@adam\_bear1](https://forum.dynamobim.com/u/adam_bear1)\
**Post date:** [July 26, 2018, 8:44am UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/6 "2018-07-26T08:44:48Z")

</div>

@sobhan.kouhestani, when I’ve wanted to count runs I use python to write a string to a text file, and then read and adjust the text file on each run, have a look at this this code, if your writing imperative hopefully adjusting this python should be fine for you 🙂

> <https://github.com/Amoursol/dynamoPython/blob/master/helpers/helpersContinouslyAddOne.py>

---

<div class="post-metadata">

**Author:** ![Aparajit\_Pratap](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aparajit\_Pratap](https://forum.dynamobim.com/u/Aparajit_Pratap)\
**Post date:** [July 26, 2018, 3:06pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/7 "2018-07-26T15:06:11Z")

</div>

@sobhan.kouhestani I do not see any issue with the result of this graph. The expected result will be 0 for tCount returned from the Imperative block. And if you’re returning t0 from the Imperative block, it will be the current time. I see the same output of 0 for tCount returned from the imperative block in 1.3.

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 26, 2018, 7:48pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/8 "2018-07-26T19:48:44Z")

</div>

@Aparajit_Pratap Thanks for your time. But On my dynamo 1.3.2.2480 it works like a charm. please see this GIF:

 ![net-gifmaker](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/e/1e70ea8a0840ad3a8f8167c27434902d17678d77.gif)

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 26, 2018, 8:00pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/9 "2018-07-26T20:00:15Z")

</div>

@adam_bear1 Since writing in an external source need a little bit of RAM and I need every little of it, I think this would be my last bullet in the chamber. However it is a nice solution. Thank you for your contribution.  
@Dimitar_Venkov I think this is the painful truth 😃. I need to think other ways like saving it into an external source. Thanks for the response.

---

<div class="post-metadata">

**Author:** ![awilliams](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/awilliams/32/114496_2.png) [@awilliams](https://forum.dynamobim.com/u/awilliams)\
**Post date:** [July 26, 2018, 8:48pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/10 "2018-07-26T20:48:18Z")

</div>

Just to add an alternative option that doesn’t require saving to an external source (but does have the aforementioned drawback)

> [@Periodic](https://forum.dynamobim.com/t/periodic/8061/8):
>
> @visualizor You could use the Clockwork nodes Clipboard.GetFrom and Clipboard.SendTo. Only draw back is you can’t accidentally copy any text while this is running, it will fail sweat_smile

---

<div class="post-metadata">

**Author:** ![sobhan.kouhestani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sobhan.kouhestani/32/51312_2.png) [@sobhan.kouhestani](https://forum.dynamobim.com/u/sobhan.kouhestani)\
**Post date:** [July 26, 2018, 9:02pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/11 "2018-07-26T21:02:03Z")

</div>

Oh thanks @awilliams , that’s a nice one!

---

<div class="post-metadata">

**Author:** ![Aparajit\_Pratap](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aparajit\_Pratap](https://forum.dynamobim.com/u/Aparajit_Pratap)\
**Post date:** [July 28, 2018, 7:43pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/12 "2018-07-28T19:43:19Z")

</div>

@sobhan.kouhestani sorry, I didn’t see that you were running in periodic mode. Unfortunately the old behavior in 1.3 will not be reproducible anymore in 2.0.

In 1.3 variables defined in the outer scope could be modified within the inner imperative scope. Therefore variables “t0” and “tCount” would update once written inside the imperative block and every time, “time” changed and the imperative block re-executed, the previously updated values of “t0” and “tCount” would be reused.

However, in 2.0 we changed the behaviour of imperative blocks and made outer variables read-only within them. This means that these variables are now copied and used as if they were local to the imperative block scope. Therefore when “t0” and “tCount” are changed in imperative code, only their local copies are modified and thus their new values do not reflect outside the imperative scope. Subsequently whenever the imperative code re-executes upon change of “time”, “t0” and “tCount” are reset to `null` (in the outer associative scope), copied and reused in the imperative scope thus overwriting their previous states.

These changes were made to simplify complex associative update semantics between associative and imperative code and to make writing DesignScript in code block nodes more coherent to users. A lot of them do not make use of associative update workflows like in this case.

---

<div class="post-metadata">

**Author:** ![szymonczykwin](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@szymonczykwin](https://forum.dynamobim.com/u/szymonczykwin)\
**Post date:** [May 28, 2021, 12:38pm UTC](https://forum.dynamobim.com/t/a-counter-for-number-of-runs/24090/13 "2021-05-28T12:38:39Z")

</div>

![counter](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/4/b4fa739e9a55f51c10d41bba93c4d4981e98febe.png)  
Hello, for my purpose i create something like this. Maybe someone beginner can use this solution 🙂
