VTKPythonAlgorithmBase decorator for 1 or 2 params?

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.
Thanks!
Aron

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.

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"
                        label="Scalars"
                        name="SelectInputScalars"
                        number_of_elements="5">
    <ArrayListDomain attribute_type="Scalars"
                     name="array_list">
      <RequiredProperties>
        <Property function="Input"
                  name="Input" />
      </RequiredProperties>
    </ArrayListDomain>
    <Documentation>The value of this property contains the name of the
    scalar array from which to perform thresholding.</Documentation>
  </StringVectorProperty>

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.