Paraview python script equivalent File-> save Data

I would like to automate the export of csv files from vtk / vtu files.

I am currently following these steps:

  • open paraview
  • upload to a pvd file that stores information about all vtu files (one for each time step in my PDE simulation)
  • go to the properties tab on the left, click "apply"
  • File-> save data ... specify the name of the base file, select "points" and "write all the timestamps"

this writes a csv file for each temporary file named basefilename # timestepno # .csv

Is there a way to do this from the command line (there is no X server on the computer that does the calculations), for example using the python interface?

+4
source share
2 answers

Try the following steps in a Python shell in the user interface or using 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() 
+6
source

I had a similar problem with pvtu files and resolved with the script below. I am running the script using execfile ("SCRIPTNAME") in Paraview -> Tools -> Python Shell. Hope this helps.

- Reinhard

 from paraview.simple import * import os """Function that counts number of files with specific extension in directory """ def directory(path,extension): list_dir = [] list_dir = os.listdir(path) count = 0 for file in list_dir: if file.endswith(extension): # eg: '.txt' count += 1 return count """Choose input/output directory and filenames""" pvtu_input_directory = "thin_1000_0.4/mesh/" csv_output_directory = "thin_1000_0.4/csv/" input_filename_root = "output" output_filename_root = "output" """ Create output directory """ os.system('mkdir '+csv_output_directory) """Start Loop over all files """ number_of_pvtu = directory(pvtu_input_directory,'.pvtu') for index in range(1,number_of_pvtu): in_filename = input_filename_root + "%0.4d" % index+".pvtu" out_filename = output_filename_root + "%0.4d" % index +".csv" loadfile = pvtu_input_directory + in_filename writefile = csv_output_directory + out_filename r = XMLPartitionedUnstructuredGridReader( FileName=loadfile) writer = CreateWriter(writefile,r) writer.FieldAssociation = "Points" writer.UpdatePipeline() """ That it. """" 
+4
source

Source: https://habr.com/ru/post/1493410/


All Articles