Help on a python programmable filter plugin

Dear all,
I’m trying to write a compiled plugin based on python programmable filter (following the example in ) to build a reader of a specific hdf5 file.
This reader should have a GUI to choose with a slider an item in a numbered set of objects and the min-max of this slider should dinamically be set depending on the input file content.
I’ve already written the requestData python script that generates an unstructured grid item by reading one of the objects described in the input file by mean of an integer index passed to the script using a SetParameter command associated in the xml file with an IntVectorProperty.
To define the limits of the slider I use an IntRangeDomain specifier in the xml that points to another information_only IntVectorProperty with an associated command GetRange that is a method I’ve added to my new class derived from vtkPythonProgrammableFilter class (using the macro vtkGetVector2Macro) to retrieve a Range vector added as a private attribure to my class.

Everythng seems to be ok if I add a C++ RequestInformation function to populate my Range attribute, but my question is: is it possible to populate this attribute through a python RequestInformation script instead of a C++ function? It would be very preferable as with a few h5py lines I can retrieve needed values instead of using libhdf5 from C++ function.

I’ve tried to find a method from python script to access to my class attributes but I haven’t found a way.

I hope to have been clear enough. Thank you in advance for any help.


I’d recommend you look at the new approach of using PythonAlgorithms.



Dear Utkarsh,
I’ve looked at those examples but I’ve not understood how I should use decorators to set not constant range for an IntVector but derived from any other function.
Could you please show me an example?


sure thing…I’ll update the example and get back to you.

it turns out that it wasn’t supported by the current implementation of PythonAlgorithms as well!

That got me down the path of fixing the issue (and doing some other code cleanups).

Here’s an MR that fixes it:
If the tests pass, then this should make it into 5.7 release. After which something like the following should do the trick:

class MySource(VTKPythonAlgorithmBase):

    @smproperty.doublevector(name="ValueRangeInfo", information_only="1")
    def GetValueRange(self):
        print("getting range: (0, 100)")
       # this should be setup in `RequestInformation`, if being read
       # from a file. This will be called `RequestInformation` but before
       # `RequestData`.
        return (0, 100)

    @smproperty.doublevector(name="Value", default_values=[0.0])
        """<DoubleRangeDomain name="range" default_mode="mid">
                    <Property name="ValueRangeInfo" function="RangeInfo" />
    def SetValue(self, val):
	        print("settings value:", val)

1 Like

Thank you very much for this.

When is 5.7 release expected to be downloadable? In the meantime is it sufficient to patch and recompile 5.6.0 superbuild with modifications you’ve done in your MR or anything else in 5.7 is necessary to get it working?


I’ve just tried to merge the files you changed in the commit above into the 5.6.0 superbuild I had already built and your example seems to work well. Thanks

But I’ve another question:

In my GUI I would like to have a dropdown list (an IntVector) to chose a parameter and the value set by this interactor should be used by the function that evaluates the range for the slider (before pressing Apply of course).
Is it possible to set some property to track the event of changing dropdown list choose to execute a function automatically?

Thanks again

I’m going on with my plugin based on PythonAlgorithms methods (according to Utkarsh suggestion) and now I’m trying to put a dropDownList which available choices are to be populated at runtime (depending on the content of the file I’m going to read).

I’ve tried with these lines in my plugin:

@smproperty.stringvector(name="AvailableAxis", information_only="1")
def GetAvailableAxis(self):
    return (self._availableAxis)

@smproperty.stringvector(name="Axis", number_of_elements="1")
    """ <StringListDomain name="axisChoice">
                    <Property name="AvailableAxis"
def SetAxis(self, val):
    self._axis = val

where self._availableAxis is assigned in RequestInformation (I’ve tried both with a list of strings and with a vector of strings).

This method seems to be wrong as I see in the GUI the dropDown list but it’s gray and not clickable.

In case of dropDown list with fixed available choices I’ve tried with

@smproperty.intvector(name="Axis", default_values=[0])
    """ <EnumerationDomain name="enum">
        <Entry value="0" text="X"/>
        <Entry value="1" text="Y"/>
        <Entry value="2" text="Z"/>

and everything seems OK, but I would like to have only valid choices for the file I’m reading and not a fixed list.

Thank you for any help on this topic.

PS my previous question about having the slider limits automatically updating when I choose which axis in the dropdown list without pressing Apply is still useful…

This needed another quick fix (available here) following which your StringVectorProperty code should work. The widget was showing up disabled since the information property ended up picking only the first string from the returned list of strings. The fix referenced addresses that.