# vtkThreshold not working with vtkMultiBlockDataSet?

**URL:** https://discourse.vtk.org/t/vtkthreshold-not-working-with-vtkmultiblockdataset/5406
**Category:** Support
**Created:** [March 19, 2021, 1:24am UTC](https://discourse.vtk.org/t/vtkthreshold-not-working-with-vtkmultiblockdataset/5406 "2021-03-19T01:24:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [March 19, 2021, 1:24am UTC](https://discourse.vtk.org/t/vtkthreshold-not-working-with-vtkmultiblockdataset/5406/1 "2021-03-19T01:24:41Z")

</div>

I’m trying to threshold datasets in a vtkMultiBlockDataSet, but the filter returns a None type - I’m working in Python 3.8.2 and vtk 9.0.1

The code fragment is shown below and export is returned as None

The input is a vtkMultiBlockDataSet containing vtkUnstrucutredGrids. I’ve exported it and confirmed using Paraview that it’s in good shape - and I can do the threshold in Paraview.

Does vtkThrehold support multiblock datasets?

Thanks in advance for amy help…

```
threshold_filter = vtk.vtkThreshold()
threshold_filter.SetInputData(mesh)
threshold_filter.ThresholdByLower(tolerance)
threshold_filter.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "Distance")
threshold_filter.Update()
export = threshold_filter.GetOutput()
```

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [March 19, 2021, 6:25pm UTC](https://discourse.vtk.org/t/vtkthreshold-not-working-with-vtkmultiblockdataset/5406/2 "2021-03-19T18:25:08Z")

</div>

Yeaa, don’t do that. Change your last line to this and it should work.

```python
export = threshold_filter.GetOutputDataObject(0) # Output port: 0

```

**Why?**  
`vtkThreshold` sub-classes `vtkUnstructuredGridAlgorithm`. If you look at it’s [`::GetOutput()`](https://vtk.org/doc/nightly/html/classvtkUnstructuredGridAlgorithm.html#a70bcf7ad3343c78ea047583f92a15021) method, it returns an unstructured grid instead of a multi-block dataset. It tries to down-cast the multi-block dataset output to an unstructured grid. Doing that in C++ gives a `nullptr`, hence you get `None` 🙂

[`::GetOutputDataObject()`](https://vtk.org/doc/nightly/html/classvtkAlgorithm.html#a4cb9f809072a01646f39a168db7a5b5e) returns the real data object. Lucky for you the wrappers take care of the down-cast magic and you get a multiblock dataset

```python
>>> threshold_filter.GetOutputDataObject(0))
(vtkmodules.vtkCommonDataModel.vtkMultiBlockDataSet)0x7f94baaebb20

```

Hth

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [April 2, 2021, 6:50am UTC](https://discourse.vtk.org/t/vtkthreshold-not-working-with-vtkmultiblockdataset/5406/3 "2021-04-02T06:50:51Z")

</div>

Thanks @jaswantp!!! That makes sense.  
In fact, I worked around the issue by just iterating over the blocks in the mbds and calling threhold on the individual; ugrids.  
Then last night I discovered vtkPythonAlgorithm… and as I worked my way through that I noticed that Algorithms don’t actually support GetOutput()… which helped me understand some issues about using GetOutput(), GetOutputDataObject() that I hadn’t really taken on board before…

Doug

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [April 7, 2021, 3:18pm UTC](https://discourse.vtk.org/t/vtkthreshold-not-working-with-vtkmultiblockdataset/5406/4 "2021-04-07T15:18:16Z")

</div>

Good to know you found a solution.

> In fact, I worked around the issue by just iterating over the blocks in the mbds and calling threhold on the individual; ugrids.

You are duplicating whatever the vtk library already does automatically. vtkCompositeDataPipeline (the default pipeline for almost every vtk filter) already does this for you when input is a multi-block dataset and puts those blocks into an output multiblock dataset… You could iterate over this output rather than calling an update in a python loop for each block!
