I have a VTK file containing 83 points, and I’m trying to use the Python VTK module (no Paraview, no NumPy) to save this data as a CSV file. After looking at a variety of examples, I wrote a script which aims to read the VTK file in as vtkPolyData, create a vtkTable from the vtkPolyData, and write the vtkTable to a CSV file.
My problem is that the resulting CSV file is empty. My script is as follows:
import vtk fileIn = 'myPoints.vtk' fileOut = 'myTable.csv' reader = vtk.vtkGenericDataObjectReader() reader.SetFileName(fileIn) reader.Update() table = vtk.vtkDataObjectToTable() table.SetInputConnection(reader.GetOutputPort()) table.SetFieldType(1) # "point data" = 1 table.Update() writer = vtk.vtkDelimitedTextWriter() writer.SetFileName(fileOut) writer.SetInputConnection(table.GetOutputPort()) writer.Update() writer.Write()
I am converting the vtkPolyData to vtkTable because vtkDelimitedTextWriter() expects a vtkTable. I learned that the table’s field type is set to Point Data with “1” via the vtkDataObjectToTable documentation.
If you have any thoughts about why the resulting CSV file is empty, or suggestions as to how to export PolyData to CSV correctly, I would be most appreciative.