I have a ParaView reader plugin in Python, which stores the path to the opened file. I want to implement various operations on the file that was read by the reader. So I write one filter for each operation. This way, I have to propagate the file path from the reader to the filter in the pipeline. The file path is a Python string.
Essentially, this is a very similar question to this one and to this one. I tried various approaches, but I am wondering if there exists a simpler one.
In all the approaches, the idea is that the custom data (here: file path string) is set as a vtkInformation key in theRequestInformation method of the reader, and fetched from the RequestInformation method of the filter.
Approaches:
-
Pass as a string key
key = vtkInformationStringKey.MakeKey('key', 'defaultValue')The problem is that the filter fetched the default value from the key, not the value that was set in the reader. According to this answer, this is expected. But why, why can’t I set/retrieve a string this way?
-
Pass as a
vtkFieldData
In his blog post (code here), Berk Geveci usesvtkInformationDataObjectMetaDataKeyto pass metadata. However, you can only associate VTK data objects with that key, so no string. The solution is to store your Python string in avtkStringArrayand add thatvtkStringArrayobject to the field data of a VTK object. Additional complexity: it must be wrapped for Python with a dataset adapter.
In the initializer of the reader, I allocate a wrapped polydata object (could be a different VTK data object, we just need it for itsvtkFieldDatamember):self._filepath = None # will store the file path obtained via ParaView self._dsa = dataset_adapter.WrapDataObject(vtkPolyData())In the
RequestInformationmethod of the reader:# Wrap the Python string array = vtkStringArray() array.SetName('key') array.SetNumberOfTuples(1) array.SetValue(0, self._filepath) # String as VTK field data self._dsa.GetFieldData().AddArray(array) # Set it as information key value outInfo.Set(key, self._dsa.VTKObject)In the
RequestInformationmethod of the filter:recovered = dataset_adapter.WrapDataObject(inInfo.Get(key)).GetFieldData().values()[0].GetValue(0) -
Use
KEYS_TO_COPY()for custom keys. I haven’t tried this approach, but it seems to be less general.
Approach 2 works for me, but it is an overkill: many layers of wrapping just to pass a simple string down the pipeline. What is the recommended way of doing it in 2026?