# Show text field changing every time step from programmable filter

**URL:** https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469
**Category:** ParaView Support
**Created:** [March 14, 2019, 1:27pm UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469 "2019-03-14T13:27:21Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![gromaxe](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/g/90ced4/32.png) [@gromaxe](https://discourse.paraview.org/u/gromaxe)
#### Post date: [March 14, 2019, 1:27pm UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469/1 "2019-03-14T13:27:21Z")

</div>

Hello everyone!  
Now I’m trying to get time in YYYY-MM-DD format for animation via programmable filter ( I still haven’t figured out how to write it to new variable, but i’m working on it).

Having a variable same length as number of timesteps, can I write contents of this variable to label (changing along with timestep)?

In raw files (netcdf) time has time like this: “01.01.1948 - 01:00:00”, but now i have to change timeaxis for Paraview.

So, main question is: is it possible to make text source from variable and change it according to timestep?

Side question is, how to make a new variable out of timesteps via programmable filter?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [March 14, 2019, 2:07pm UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469/2 "2019-03-14T14:07:49Z")

</div>

> [@gromaxe](#):
>
> So, main question is: is it possible to make text source from variable and change it according to timestep?

Yes. Use the **Python Annotation** filter. Attach it to your data source with the field data representing time. If it is named “Time”, your **Python Annotation** filter should be set to `Time[t_index]` where `t_index` is the index of the current timestep selected in ParaView.

---

<div class="post-metadata">

### Author: ![gromaxe](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/g/90ced4/32.png) [@gromaxe](https://discourse.paraview.org/u/gromaxe)
#### Post date: [March 14, 2019, 2:11pm UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469/3 "2019-03-14T14:11:56Z")

</div>

> [@cory.quammen](#):
>
> `Time[t_index]`

That’s great!  
Also, with this I don’t need programmable filter, just change date format as i want

---

<div class="post-metadata">

### Author: ![gromaxe](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/g/90ced4/32.png) [@gromaxe](https://discourse.paraview.org/u/gromaxe)
#### Post date: [March 15, 2019, 6:58am UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469/4 "2019-03-15T06:58:21Z")

</div>

Once more, thanks for an answer, and I’ve got following question:

Having time units like _Hours since …_, how to get date from timestep value?  
It is possible via datetime Python module, but I haven’t found the way to do it with Python Annotation. Is it possible?

* * *

And some story with additional questions, that made me ask this:

After adding timeaxis to my file I have timesteps like  
19820106  
19820111  
…  
19820131  
19820204

They are interpreted by Paraview as int, and this is source of my problem.

If i choose Animation View Mode _Sequence_, i get timestep values between 19820131 and 19820204, for example 19820173, which is bad.

If i choose Animation View Mode _Snap To TimeSteps_ and set _Camera_ to _Orbit_, while transfer from 19820131 19820204 it jumps a lot and animation is not smooth.

Now I’m trying to build pipeline for visualizing model files with minimum (ideally, no) preprocessing, so I’m trying to avoid file conversions. Maybe, the best solution would be just configurate a reader with all specifications that I want.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [April 11, 2019, 3:34pm UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469/5 "2019-04-11T15:34:51Z")

</div>

> [@gromaxe](#):
>
> Having time units like _Hours since …_ , how to get date from timestep value?

I’m afraid I don’t know what your timestep values represent, and I’m not that versed in Python date handling to offer suggestions.

> [@gromaxe](#):
>
> They are interpreted by Paraview as int, and this is source of my problem.

I think you are saying ParaView is displaying a time value that isn’t in your dataset. It is displaying the time requested in ParaView, but the data displayed is the closest available timestep, so there is indeed a mismatch in that regard. I suppose you could round the ParaView time to the closest one in your time array with some Python function.

---

<div class="post-metadata">

### Author: ![Ying](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/y/fbc32d/32.png) [@Ying](https://discourse.paraview.org/u/Ying)
#### Post date: [March 15, 2022, 8:25pm UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469/6 "2022-03-15T20:25:43Z")

</div>

> [@cory.quammen](#):
>
> the index of the current timestep selected in ParaView

Hi Cory, I know it is a post long time ago, but I have the same problem right now. I want to add a notation “time” varying with time step into the render view, and now I obtain “time” as a dictionary, which looks like:

```auto
{0: '1250.0', 1: '1250.5', 2: '1251.0', 3: '1251.5', 4: '1252.0', 5: '1252.5', 6: '1253.0', 7: '1253.5', 8: '1254.0', 9: '1254.5'}

```

And as you suggested, I use Python Annotation filter in scripting:

```auto
pythonAnnotation1 = PythonAnnotation(Input=velocity)
pythonAnnotation1.Expression = time[t_index]
pythonAnnotation1Display = Show(pythonAnnotation1, renderView1)

```

But I received the error “name ‘t\_index’ is not defined”. It seems that I need to **get the current time step** used in active view. Do you know how to do that in paraview?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [March 15, 2022, 9:12pm UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469/7 "2022-03-15T21:12:06Z")

</div>

> [@Ying](#):
>
> `pythonAnnotation1.Expression = time[t_index]`

Make this line

```python
pythonAnnotation1.Expression = "time[t_index]"

```

instead. The expression needs to be a string. The way you have it tries to evaluate `time[t_index]` before setting the value of the `Expression` attribute, but `t_index` is not defined in your script.

---

<div class="post-metadata">

### Author: ![Ying](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/y/fbc32d/32.png) [@Ying](https://discourse.paraview.org/u/Ying)
#### Post date: [March 15, 2022, 9:32pm UTC](https://discourse.paraview.org/t/show-text-field-changing-every-time-step-from-programmable-filter/1469/8 "2022-03-15T21:32:04Z")

</div>

Hi Cory,  
I use `t_index = animationScene1.TimeKeeper.TimestepValues` to get the time step, which has a type of `<class 'paraview.servermanager.VectorProperty'> `, and looks like `[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]` (since I have 10 vtk files for 10 timesteps).

I add the quotation mark for time[t\_index], and receive the error:

```auto
NameError: name 'time' is not defined

```

But I have define the variable time in the above in python scripting.

I guess I need to insert the variable “time” into the paraview.simple module? Cause I have the same problem when doing this in GUI. So the questions seems to be how to read variable “time” in paraview…
