Python filter proxy does not update property

python

#1

Hello,

I’m trying to create a proxy for a python filter. On the client side, I would like the proxy to be able to provide an id. I tried 2 different property mechanisms for that purpose, but I am facing 2 issues:

  1. The proxy property is not updated after the pipeline has been updated: see GetID2 below.
  2. I did not find a proper way to implement a property getter that fits the data type: below GetID never returns an id, always None.

I work with paraview 5.6 and python 3.6 (all from anaconda).

The simplified proxy code, the file is named proxies.py, I used a source filter just for the demonstration :

from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
from paraview.util.vtkAlgorithm import smproxy, smproperty, smdomain
from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet


@smproxy.source()
class IDProxy(VTKPythonAlgorithmBase):

    def __init__(self, *args, **kwargs):
        super().__init__(nInputPorts=0,
                         nOutputPorts=1,
                         outputType='vtkMultiBlockDataSet')
        self.id = 0

    def RequestData(self, request, inInfo, outInfo):
        self.id += 1
        print('RequestData: id=', self.id)
        return 1

    @smproperty.xml(xmlstr='''
   <IdTypeVectorProperty
       command="GetID"
       information_only="1"
       name="IDInfo"
       si_class="vtkSIDataArrayProperty"/>
   <IdTypeVectorProperty
       command="GetID"
       information_property="IDInfo"
       name="ID"
       si_class="vtkSIDataArrayProperty">
     <ArraySelectionDomain name="array_list">
       <RequiredProperties>
         <Property function="ArrayList" name="IDInfo"/>
       </RequiredProperties>
     </ArraySelectionDomain>
   </IdTypeVectorProperty>
''')
    def GetID(self):
        print('GetID: id=', self.id)
        return self.id

    @smproperty.dataarrayselection(name="ID2")
    def GetID2(self):
        from vtkmodules.vtkCommonCore import vtkDataArraySelection
        x = vtkDataArraySelection()
        print('GetID2: id=', self.id)
        x.AddArray('%d' % self.id)
        return x

The test script:

from pathlib import Path
from paraview import simple
simple.LoadPlugin(str(Path(__file__).parent / 'proxies.py'))
from paraview.simple import IDProxy
proxy = IDProxy()
print('ID id=', proxy.ID)
print('ID2 id=', proxy.ID2)
proxy.UpdatePipeline()
print('ID' id=, proxy.ID)
print('ID2 id=', proxy.ID2)

The output I get:

GetID2: id= 0
GetID: id= 0
GetID: id= 0
GetID2: id= 0
ID id= None
ID2 id= ['0']
RequestData: id= 1
ID id= None
ID2 id= ['0']

Thanks for any help.