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.