Writing VTK file from Python for use in Paraview

3.2k Views Asked by At

I have a Unstructured Grid VTK legacy file which is read using Python and the velocity calculated and stored as a Numpy array. I am looking to firstly export the array to its own VTK file for use in Paraview.

1

There are 1 best solutions below

2
On BEST ANSWER

Your VTK_data is, as the error said, a vtkFloatArray. It does not have a GetOutput() method and it cannot be written as an UnstructuredGrid.

You have to add your array to your dataset data and then you can write data with the writer:

VTK_data.SetName("VELOCITY")
data.GetPointData().AddArray(VTK_data)

writer = vtk.vtkUnstructuredGridWriter()
writer.SetFileName("Output.vtk")
writer.SetInputData(data)
writer.Update()
writer.Write()