# Filter XML for Input Array Values from Optional Input

**URL:** https://discourse.paraview.org/t/filter-xml-for-input-array-values-from-optional-input/13366
**Category:** Development
**Created:** [November 28, 2023, 5:52pm UTC](https://discourse.paraview.org/t/filter-xml-for-input-array-values-from-optional-input/13366 "2023-11-28T17:52:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![moritz-h](https://discourse.paraview.org/user_avatar/discourse.paraview.org/moritz-h/32/6862_2.png) [@moritz-h](https://discourse.paraview.org/u/moritz-h)
#### Post date: [November 28, 2023, 5:52pm UTC](https://discourse.paraview.org/t/filter-xml-for-input-array-values-from-optional-input/13366/1 "2023-11-28T17:52:35Z")

</div>

I have a custom plugin with a filter which has two inputs, the second input is optional. I want to add a widget to select input arrays on the second optional input if it is present and need to write the XML for this.  
Adding a StringVectorProperty as described in the docs ([ParaView: Plugin Howto](https://kitware.github.io/paraview-docs/nightly/cxx/PluginHowto.html) at Drop Down List with Values from Input Arrays) works only if both inputs are connected. If the optional input is empty I get a lot of `Index out of range: 0` errors from vtkSMArrayListDomain. How I can tell the StringVectorProperty widget that the input is optional and may nothing is select?  
I also tried to hide the widget based on the InputProperty state, but this XML leads to `ProxyProperty not properly specified in XML.`  
`<PropertyWidgetDecorator type="GenericDecorator" mode="visibility" property="Input1" value="1"/>`

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [November 29, 2023, 8:36am UTC](https://discourse.paraview.org/t/filter-xml-for-input-array-values-from-optional-input/13366/2 "2023-11-29T08:36:18Z")

</div>

> [@moritz-h](#):
>
> the second input is optional

There is (sadly) no such thing as optional secondary inputs in ParaView.

---

<div class="post-metadata">

### Author: ![moritz-h](https://discourse.paraview.org/user_avatar/discourse.paraview.org/moritz-h/32/6862_2.png) [@moritz-h](https://discourse.paraview.org/u/moritz-h)
#### Post date: [November 29, 2023, 4:08pm UTC](https://discourse.paraview.org/t/filter-xml-for-input-array-values-from-optional-input/13366/3 "2023-11-29T16:08:55Z")

</div>

> [@mwestphal](#):
>
> There is (sadly) no such thing as optional secondary inputs in ParaView.

But that part is actually working for a long time already:

```cpp
this->SetNumberOfInputPorts(2);

```

```cpp
int vtkFooBar::FillInputPortInformation(int port, vtkInformation* info) {
    if (port == 0) {
        info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkRectilinearGrid");
        return 1;
    }
    if (port == 1) {
        info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
        info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
        return 1;
    }
    return vtkDataSetAlgorithm::FillInputPortInformation(port, info);
}

```

I can then either connect or not connect the second input. Only part not working is using StringVectorProperty to select arrays on the optional input if nothing is connected.

Nevertheless, I think for my specific usecase I found a workaround. As I require the data arrays I want from different datasets to have the same size anyway I can just use the Append Attributes filter before my filter and then handle the data as additional optional arrays from a single input.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [November 29, 2023, 4:10pm UTC](https://discourse.paraview.org/t/filter-xml-for-input-array-values-from-optional-input/13366/4 "2023-11-29T16:10:03Z")

</div>

> [@moritz-h](#):
>
> But that part is actually working for a long time already:

This is VTK, not ParaView.

Great that you found a solution.
