# How to execute a python script every step of an animation?

**URL:** https://discourse.paraview.org/t/how-to-execute-a-python-script-every-step-of-an-animation/4621
**Category:** ParaView Support
**Tags:** vtk, python
**Created:** [June 18, 2020, 7:43pm UTC](https://discourse.paraview.org/t/how-to-execute-a-python-script-every-step-of-an-animation/4621 "2020-06-18T19:43:47Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![leopessanha](https://discourse.paraview.org/user_avatar/discourse.paraview.org/leopessanha/32/289_2.png) [@leopessanha](https://discourse.paraview.org/u/leopessanha)
#### Post date: [June 19, 2020, 10:41am UTC](https://discourse.paraview.org/t/how-to-execute-a-python-script-every-step-of-an-animation/4621/3 "2020-06-19T10:41:25Z")

</div>

Thank you, Utkarsh but it is not exactly what I am looking for because the variables of the code are reset every timestep.

The goal is to show the date of the simulation in the screen, using a start date and updating it every timestep, since the animation track run every timestep I’ve removed the part with TimeKeeper.Time

**Python animation try code:**

```auto
day = 28
month = 1
year = 2020
hour = 0
minute = 0
unitOfTime = 15

def start_cue(self):
    global day
    global month
    global year
    global hour
    global minute
    global unitOfTime
    minute += unitOfTime
    if(minute == 60 ):
        hour+=1
        minute = 0
        if(hour == 24):
          day+=1
          hour = 0
        if(day == 32):
          month+=1
          day = 1
        if(month == 13):
          year+=1
          month = 1
    return str(day) + '/' + str(month) + '/' + str(year) + ' ' + str(hour) + ':' + str(minute)

def tick(self): pass
def end_cue(self): pass

```

**Code before the changes:**

```auto
from paraview.simple import *
from paraview.vtk import vtkCommand

rv = GetActiveView()
tk = GetTimeKeeper()
dia = 28
mes = 1
ano = 2020
hora = 0
minuto = 0
unidade = 15
timeStep = tk.Time
nextTimeStep = timeStep+1

def dataDia():
    global dia
    global mes
    global ano
    global hora
    global minuto
    global unidade
    global timestep
    global nextTimeStep
    if(timeStep >= nextTimeStep):
        nextTimeStep+=1
        minuto += unidade
        if(minuto == 60 ):
          hora+=1
          minuto = 0
        if(hora == 24):
          dia+=1
          hora = 0
        if(dia == 32):
          mes+=1
          dia = 1
        if(mes == 13):
          ano+=1
          mes = 1
    return str(dia) + '/' + str(mes) + '/' + str(ano) + ' ' + str(hora) + ':' + str(minuto)

def callback(caller, event):
    text1.Text = dataDia()
    timeStep = tk.Time

text1 = Text()
text1Display = Show(text1, rv, 'TextSourceRepresentation')
rv.GetInteractor().AddObserver(vtkCommand.AnimationCueTickEvent, callback, 1.0)

```

---

_[View the full topic](https://discourse.paraview.org/t/how-to-execute-a-python-script-every-step-of-an-animation/4621)._
