Populate a StringVector from a file

Hi Mathieu,

Thanks for your reply.

I’ll check out the link you provided. The Default Value tag allows me to set the initial value of the StringVector before the user selects a file. I can’t see a way of updating this and redrawing the StringVector after a user picks a file with the chooser?

This is what I have so far:

from paraview.util.vtkAlgorithm import (
VTKPythonAlgorithmBase,
smdomain,
smhint,
smproperty,
smproxy,
)

from vtkmodules.numpy_interface import dataset_adapter as dsa
from vtkmodules.vtkCommonDataModel import (vtkDataSet, vtkCompositeDataSet, vtkMultiBlockDataSet, vtkUnstructuredGrid)

@smproxy.filter(label=“Myfilter”)
@smhint.xml(r"".format(os.path.join(PLUGINDIR,‘icons’,‘myicon.png’)))
@smhint.xml("")
@smproperty.input(name=“Input”, port_index=0)
@smdomain.datatype(dataTypes=[“vtkMultiBlockDataSet”], composite_data_supported=True)
class Myfilter(VTKPythonAlgorithmBase):
def init(self):
VTKPythonAlgorithmBase.init(self, nInputPorts=1, nOutputPorts=1, inputType=“vtkMultiBlockDataSet”, outputType=“vtkMultiBlockDataSet”)
self._text = None
self._filename = None

@smproperty.stringvector(name="Text")
@smdomain.filelist()
@smhint.filechooser(
    extensions=['txt'], file_description="Text File"
)
def SetFileName(self, filename):
    if self._filename != filename:
        self._filename = filename
        self.Modified()

@smproperty.stringvector(name="TextBox", default_values="Enter TEXT here or load a file below")
@smhint.xml(r"<Widget type='multi_line'/>")
def SetText(self, text):
    if self._text != text:
        self._text = text
        self.Modified()

def RequestData(self, request, inInfoVec, outInfoVec):

    thisMultiblock = dsa.WrapDataObject(vtkMultiBlockDataSet.GetData(inInfoVec[0]))
    output = dsa.WrapDataObject(vtkMultiBlockDataSet.GetData(outInfoVec))

    self.SetProgressText('Processing Multiblock')
    self.UpdateProgress(0.1)
    
    if self._filename is not None:
        with open(self._filename,'r') as f:
            self._text = ''.join(f.readlines())

    thisNewMultiblock = myClass.myFunction(thisMultiblock,self._text).multiblock

    output.ShallowCopy(thisNewMultiblock)
    
    self.SetProgressText('Done')
    self.UpdateProgress(1.0)
    return 1