# Help needed with vtkSelectionNode and Query

**URL:** https://discourse.paraview.org/t/help-needed-with-vtkselectionnode-and-query/6008
**Category:** Development
**Tags:** python, vtk
**Created:** [December 8, 2020, 2:12pm UTC](https://discourse.paraview.org/t/help-needed-with-vtkselectionnode-and-query/6008 "2020-12-08T14:12:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Loic](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/l/e9c0ed/32.png) [@Loic](https://discourse.paraview.org/u/Loic)
#### Post date: [December 8, 2020, 2:12pm UTC](https://discourse.paraview.org/t/help-needed-with-vtkselectionnode-and-query/6008/1 "2020-12-08T14:12:08Z")

</div>

Hi,

I’m working on a Python plugin for ParaView.  
I’m using the ResampleWithDataset filter and i need to deal with invalid nodes, where the field vtkValidPointMask is set to 0.  
I’m trying to use vtkSelectionNode to extract these nodes, but I can’t get it to work.

Here is a simple test case:

```
import numpy as np
import vtk
import vtk.numpy_interface.dataset_adapter as dsa

# ------------------------------------------
# ***This part create a simple dataset*** 

# Create a simple sphere
sphereSource = vtk.vtkSphereSource()
sphereSource.SetPhiResolution(48)
sphereSource.SetThetaResolution(32)

sphereSource.Update()
obj_sphere = sphereSource.GetOutput()

# Get points coordinate
Coords = dsa.vtkDataArrayToVTKArray(obj_sphere.GetPoints().GetData())

# A a test field named vtkValidPointMask
aval = np.arctan2(Coords[:, 0], Coords[:, 1])
tval = (2+np.cos(8*np.pi*Coords[:, 2]) - np.sin(3*aval))/4
obj_sphere.GetPointData().AddArray( dsa.numpyTovtkDataArray(tval, "vtkValidPointMask"))

## Write as vtp file
vf = vtk.vtkXMLPolyDataWriter()
vf.SetFileName("shere.vtp")
vf.SetInputDataObject(obj_sphere)
vf.Write()

## ---------------------------------------------
## ***Here start the test*** 

## lecture des fichiers
#vf = vtk.vtkXMLPolyDataReader()
#vf.SetFileName("sphere.vtp")
#vf.Update()
#obj_sphere = vf.GetOutput()

selectionNode = vtk.vtkSelectionNode()
selectionNode.SetFieldType(vtk.vtkSelectionNode.VALUES)
selectionNode.SetContentType(vtk.vtkSelectionNode.QUERY)
selectionNode.SetQueryString("vtkValidPointMask >= 0.5")

selection = vtk.vtkSelection()
selection.AddNode(selectionNode)

extractSelection = vtk.vtkExtractSelection()
extractSelection.SetInputData(0, obj_sphere)
extractSelection.SetInputData(1, selection)
extractSelection.Update()

obj_extract = extractSelection.GetOutput()

print('Sphere : {} points'.format(obj_sphere.GetNumberOfPoints()))
print('Extract : {} points'.format(obj_extract.GetNumberOfPoints()))

```

Have you got any hint to make this work?

Thanks a lot!  
Best regards,

Loic

---

<div class="post-metadata">

### Author: ![jfavre](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jfavre](https://discourse.paraview.org/u/jfavre)
#### Post date: [December 9, 2020, 11:19am UTC](https://discourse.paraview.org/t/help-needed-with-vtkselectionnode-and-query/6008/2 "2020-12-09T11:19:29Z")

</div>

I recommend using the following code instead, in your ParaView Python Shell

> from paraview.selection import \*  
> s1 = SelectThresholds(Thresholds=[.5,1], ArrayName=‘vtkValidPointMask’, Source=GetActiveSource())  
> a = ExtractSelection(Input=GetActiveSource(), Selection=s1)  
> Show(a)

---

<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: [December 9, 2020, 12:19pm UTC](https://discourse.paraview.org/t/help-needed-with-vtkselectionnode-and-query/6008/3 "2020-12-09T12:19:19Z")

</div>

`QUERY` type selections are not directly supported by `vtkExtractSelection`. You have to use `vtkPVExtractSelection` which internally uses `vtkPythonSelector` to support these queries. You can use @jfavre suggestion. If you want a pure VTK code, you may want to use other filters like `vtkThreadhold` filter or its ilk.
