# VTKPythonAlgorithmBase decorator for 1 or 2 params?

**URL:** https://discourse.paraview.org/t/vtkpythonalgorithmbase-decorator-for-1-or-2-params/1635
**Category:** Development
**Created:** [April 9, 2019, 3:51pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-decorator-for-1-or-2-params/1635 "2019-04-09T15:51:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![aron.helser](https://discourse.paraview.org/user_avatar/discourse.paraview.org/aron.helser/32/13_2.png) [@aron.helser](https://discourse.paraview.org/u/aron.helser)
#### Post date: [April 9, 2019, 3:51pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-decorator-for-1-or-2-params/1635/1 "2019-04-09T15:51:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [April 9, 2019, 4:49pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-decorator-for-1-or-2-params/1635/2 "2019-04-09T16:49:28Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![aron.helser](https://discourse.paraview.org/user_avatar/discourse.paraview.org/aron.helser/32/13_2.png) [@aron.helser](https://discourse.paraview.org/u/aron.helser)
#### Post date: [April 9, 2019, 6:31pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-decorator-for-1-or-2-params/1635/3 "2019-04-09T18:31:29Z")

</div>

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` 🙂  
I was trying to write a filter with different functionality that I could drop in as a replacement.
