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
 w.UpdatePipeline()

I get an error, when i write the script in a file named ‘convert.py’ and run it with ‘pvpython convert.py’:
Traceback (most recent call last):
File “convert.py”, line 5, in
w.CompressorType = LZMA
NameError: name ‘LZMA’ is not defined

LZMA variable name that does not exist. But you want to set the CompressorType to the String ‘LZMA’.
You are just missing the quotes.

2 Likes

Indeed, I’ve edited my post.

@vrkssai : In doubt, use the python trace method.

I don’t understand the ‘python trace method’ part.

1 Like