# Multiple .VTR files

**URL:** https://discourse.vtk.org/t/multiple-vtr-files/586
**Category:** Support
**Created:** [March 21, 2019, 4:07pm UTC](https://discourse.vtk.org/t/multiple-vtr-files/586 "2019-03-21T16:07:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![S97](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@S97](https://discourse.vtk.org/u/S97)
#### Post date: [March 21, 2019, 4:07pm UTC](https://discourse.vtk.org/t/multiple-vtr-files/586/1 "2019-03-21T16:07:37Z")

</div>

Hello,

I am after some guidance on where to go with my project…

I currently have a python pre processing file that reads a netCDF and generates a .vtr rectilinear grid which I then read in, to another python vtk file where I use contour filter to successfully render the isosurfaces.

However, I know want to render a ‘video’. I understand that rectilinear grid cannot take a 4th dimension or a timestep. So my pre processing file is going to have to output a .vtr file for each timestep. Is it then possible to read in many .vtr files into my visualisation app and to render them together as a video…

I understand this is not really a question, I am more looking for some pointer or guidance on how to combine multiple rectilinear grids to output my video

Thanks

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [March 21, 2019, 6:55pm UTC](https://discourse.vtk.org/t/multiple-vtr-files/586/2 "2019-03-21T18:55:58Z")

</div>

You should try downloading [ParaView](https://www.paraview.org) then open all of the files at once as a time series. You can then press the play button in ParaView to preview the simulation and then select _File-\>Save Animation_ to make a video. Here is a demo of what this looks like for a totally different data set (note I only open one file in this video but ParaView handles file series like yours with ease).

https://player.vimeo.com/video/294710986?app_id=122963

---

<div class="post-metadata">

### Author: ![S97](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@S97](https://discourse.vtk.org/u/S97)
#### Post date: [March 21, 2019, 7:38pm UTC](https://discourse.vtk.org/t/multiple-vtr-files/586/3 "2019-03-21T19:38:49Z")

</div>

Hi,

This is exactly want I want to recreate but using VTK. I’ve currently got it all working in para view and can see how it should look 🙂

I understand it may seem pointless what I am doing, when I can just do it para view , but it’s for my project

---

<div class="post-metadata">

### Author: ![lorensen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lorensen/32/20_2.png) [@lorensen](https://discourse.vtk.org/u/lorensen)
#### Post date: [March 21, 2019, 7:53pm UTC](https://discourse.vtk.org/t/multiple-vtr-files/586/4 "2019-03-21T19:53:25Z")

</div>

Look at the loop in this example.

You could save an image to a file in this loop. Use vtkWindowToImageFilter after the render and an image writer to save the contents of the window.  
[https://lorensen.github.io/VTKExamples/site/Python/IO/ImageWriter/](https://lorensen.github.io/VTKExamples/site/Python/IO/ImageWriter/)

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [March 21, 2019, 11:09pm UTC](https://discourse.vtk.org/t/multiple-vtr-files/586/5 "2019-03-21T23:09:32Z")

</div>

> [@S97](#):
>
> This is exactly want I want to recreate but using VTK

Ah, I thought this could be a bit of a programming endeavor and figured ParaView might be simpler.

> [@lorensen](#):
>
> You could save an image to a file in this loop. Use vtkWindowToImageFilter after the render and an image writer to save the contents of the window.

We do exactly this in [`vtki`](http://docs.vtki.org). @S97: if you like Python, you could follow one of our gif or movie creation examples:

- [vtki.org](http://docs.vtki.org/en/latest/examples/quick/plot/plot-movie.html)
- [http://docs.vtki.org/en/latest/examples/quick/plot/plot-gif.html](http://docs.vtki.org/en/latest/examples/quick/plot/plot-gif.html)
- [http://docs.vtki.org/en/latest/examples/quick/plot/plot-time-lapse.html](http://docs.vtki.org/en/latest/examples/quick/plot/plot-time-lapse.html)

or do something like this (which I hacked together quickly - there should be a more elegant way to build a reader pipeline):

```python
import vtk
import vtki

# All the VTR file names
filenames = ['foo-{}.vtr'.format(i) for i in range(4)]

reader = vtk.vtkXMLRectilinearGridReader()

def update_reader(fname):
    reader.SetFileName(fname)
    reader.Modified()
    reader.Update()

update_reader(filenames[0])
grid = vtki.wrap(reader.GetOutput())

# Create a plotter object and set the scalars to the Z height
plotter = vtki.Plotter()
plotter.add_mesh(grid, name='foo')

# setup camera and close
plotter.plot(auto_close=False)

# Open a gif
plotter.open_gif('frames.gif')

# Update Z and write a frame for each updated position
nframe = 15
for fname in filenames:
    update_reader(fname)
    print(fname)
    grid = vtki.wrap(reader.GetOutput())
    plotter.add_mesh(grid, name='foo')
    plotter.write_frame()

# Close movie and delete object
plotter.close()

```
