Shahbaz Ahmed
Shahbaz Ahmed

Reputation: 45

how to change field variable/cell values in vti file with python script

I have a vti file which contains certain geometry with hexagonal mesh. After a loading step a field variable name "concentration" changes and must be changed back zero. There is one possibility in paraview by hard way. Can any body share a way how to open, edit a field variable and overwrite a vti file with python. Thanks.

Upvotes: 1

Views: 514

Answers (1)

Nico Vuaille
Nico Vuaille

Reputation: 2488

You can use vtk python module to do that.

  1. read with vtkXMLImageDataReader
  2. Get the array to modify array = reader.GetOutput().GetCellData().GetArray("concentration")
  3. modify the array values by index: array.InsertTuple(i, 0)
  4. write back with vtkXMLImageDataWriter

See the read/write example

That is the native VTK solution. There is some other ways, as using numpy to modify the data array, or do it in ParaView python scripting

Upvotes: 2

Related Questions