paraview python scripting equivalent of File->save Data

Hans picture Hans · Jul 25, 2013 · Viewed 7.3k times · Source

I would like to automate exporting csv files from vtk/vtu files.

Right now, the steps I take are:

  • open paraview
  • load in the pvd file that stores the information about all vtu files (one for each time steps in my PDE simulation)
  • goto Properties tab on the left, hit 'apply'
  • File->save Data... provide a base file name, select 'points' and 'write all timesteps'

this writes a csv file for each timesteps with the name basefilename#timestepno#.csv

Is there a way to do this from the commandline (there's no X server on the computer that's doing the computations), eg using the python interface?

Answer

Utkarsh picture Utkarsh · Aug 1, 2013

Try the following in either the Python Shell in the UI or using the pvpython or pvbatch Python executables.

from paraview import simple
reader = simple.OpenDataFile("..../foo.pvd")
writer = simple.CreateWriter("..../foo.csv", reader)
writer.WriteAllTimeSteps = 1
writer.FieldAssociation = "Points"
writer.UpdatePipeline()