update automatic data input

Dear all

my input data is VTU, and to visualize, i need to reload my input file every minute.
is there any menu in paraview how to update automatically. so i dont need to refresh.

thank you for your help.

There is no option in menu to do that. You will need a Live Programmable Source.

in the `Script’ part, put vtkPython code to read your file

from paraview.vtk.vtkIOXML import vtkXMLUnstructuredGridReader as vtuReader
# adapt here to use the appropriate reader
reader = vtuReader()
reader.SetFileName('/path/to/file.vtu')
reader.Update()

self.GetOutputDataObject(0).ShallowCopy(reader.GetOutput())

in the second part, Script (CheckNeedsUpdate), write the conditionnal check you want. The first script will be executed only when SetNeedsUpdate(True) is called in this second script.

import time
if not hasattr(self, "_my_time"):
  setattr(self, "_my_time", time.time())

t = time.time()
lastTime = getattr(self, "_my_time")
# adapt here to set the time (in sec) you want to wait between updates
if t - lastTime > 60:
  setattr(self, "_my_time", t)
  self.SetNeedsUpdate(True)
2 Likes

thank for your help.

Hello,

Thank you very much for this valuable information!. Just for completeness, i let here the corresponding XML code to create a plugin suited for the Live Programmable Source code that you provided.

Regards

Miguel

		<StringVectorProperty 
			name="Script" 
			command="SetScript"
			number_of_elements="1"
			default_values="execfile('Path_to_the_SCRIPT_python_file')">
		</StringVectorProperty>
		
		<StringVectorProperty
			name="CheckNeedsUpdateScript"
			label="CheckNeedsUpdateScript"
			command="SetCheckNeedsUpdateScript"
			number_of_elements="1"
			default_values="execfile('Path_to_the_CheckNeedsUpdate_python_script')"
			panel_visibility="advanced">
		</StringVectorProperty>
		
		<Property name="PauseLiveSource" panel_widget="pause_livesource">
			<Documentation>
			  Pause live source.
			</Documentation>
		</Property>
		
		<Hints>
			<LiveSource />
		</Hints>
		
	</SourceProxy>
</ProxyGroup>

How does one prevent this from creating a new reader every time the script is called? I am using an OpenFOAMReader and the script creates a new one each time instead of updating the original one.

@nicolas.vuaille This works great! But is there a way to get this to work for a csv file? I would like to visualize a real time line chart of a csv file.
I can use CSVReader to read the csv file, but I don’t know how to match the output with the available output data type.

Hi,

A csv file should output a vtkTable.

Be careful, in this script you should create a VTK reader not, a ParaView reader proxy.

That makes sense, thanks! I also forgot to convert to numpy, the final code below works for my csv file:

import numpy as np
import pandas as pd
data = pd.read_csv("history.csv",sep=',')
for name in data.keys():
  array = data[name].to_numpy()
  output.RowData.append(array,
1 Like