RSwn
RSwn

Reputation: 11

Writing VTK file from Python for use in Paraview

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.

Upvotes: 0

Views: 3705

Answers (1)

Nico Vuaille
Nico Vuaille

Reputation: 2488

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()

Upvotes: 1

Related Questions