pvpython script to convert binary Legacy VTK file to some compressed version to reduce file size

I’m looking for a simple script options like:

from paraview.simple import *
r = LegacyVTKReader( FileNames=['Yourfilename.vtk'] )
SaveData('Yourfilename_binary.vtk', proxy=r)

used from: https://stackoverflow.com/a/58209834

I was wondering if there are options to compress/convert the file to some better version(like *vtu).

Cc: @mwestphal

1 Like

SaveData('Yourfilename_binary.vtu', proxy=r)

I’ve tried this but it doesn’t reduce the file size. For example, how to use the LZMA compressor like we would have in the GUI dialog box, to get the smallest file size.
my obs:
data.vtk - 2.4Mb
data.vtu- 2.5Mb
data.vtu- 1.2Mb(from paraview GUI - LZMA compressor)
I would like to use something like the last one to drastically reduce the file size. Even converting to other format is also fine with me(I need the format to have Arbitary order Lagrange Hexahedron support), but the objective is to reduce file size.

I missed the file size reduction part.

 from paraview.simple import *
 r = LegacyVTKReader( FileNames=['Yourfilename.vtk'] )
 w = XMLUnstructuredGridWriter(r)
 w.FileName = "Yourcompressedfilename.vtk"
 w.CompressorType = LZMA
 w.CompressionLevel = 9