VTKPythonAlgorithmBase decorator for 1 or 2 params?

(Aron Helser) #1

I’m working on some filters in Python using VTKPythonAlgorithmBase, and I was wondering how to decorate a method so it can take a single string argument or an array of two (or more?) strings?

If I do:

  @smproperty.stringvector(name="Scalars", default_values="param1")
  def SetFieldToFilter(self, name):

it requires one variable, and if I do:

@smproperty.stringvector(name="Scalars", number_of_elements=2, default_values=["CELLS", "param1"])
def SetFieldToFilter(self, name):

it requires two variables.

(Utkarsh Ayachit) #2

My recommendation is don’t do it :). None of the ParaView UI widgets will handle one or two arguments interchangeably. They can work with exactly 1 or 2 just fine.

As a side note, you can always use xml decorator to add raw XML of your liking.

(Aron Helser) #3

Sure, I’m fine limiting to specific args.
My motivation was trying to replicate the behavior of the Scalars input of the Threshold filter. It happened that existing code set .Scalars to either one string or two, and the filter accepted it as input. So perhaps this is unexpected? The XML is this:

  <StringVectorProperty command="SetInputArrayToProcess"
                        element_types="0 0 0 0 2"
    <ArrayListDomain attribute_type="Scalars"
        <Property function="Input"
                  name="Input" />
    <Documentation>The value of this property contains the name of the
    scalar array from which to perform thresholding.</Documentation>

I suspect some magic around SetInputArrayToProcess :slight_smile:
I was trying to write a filter with different functionality that I could drop in as a replacement.