# Filtering by cell/point ID

**URL:** https://discourse.paraview.org/t/filtering-by-cell-point-id/15694
**Category:** ParaView Support
**Created:** [November 6, 2024, 8:52pm UTC](https://discourse.paraview.org/t/filtering-by-cell-point-id/15694 "2024-11-06T20:52:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Bryce\_Richards](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bryce_richards/32/15514_2.png) [@Bryce\_Richards](https://discourse.paraview.org/u/Bryce_Richards)
#### Post date: [November 6, 2024, 8:52pm UTC](https://discourse.paraview.org/t/filtering-by-cell-point-id/15694/1 "2024-11-06T20:52:31Z")

</div>

I’m using the paraview’s python scripting capability. I’m looking for a way to filter data by cell and/or point ID, so that a chain of filters where only a subset of the mesh is of interest can run more quickly. We are using paraview as a backend mesh reader/calculator, but we’re not using the visualization capabilities now since we need that to be done in a javascript frontend (bonus question: is there a javascript/react library for paraview similar to vtkjs?)

I’ve seen paraview.simple.SelectIDs but this doesn’t seem to work for me:

```bash
point_selection = pvs.SelectIDs(IDs=point_ids, FieldType='POINT')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[33], line 1
----> 1 point_selection = pvs.SelectIDs(IDs=point_ids, FieldType='POINT')

File ~/Documents/ZooHill/Osprey/osprey-react/dev-tools-env/lib/python3.10/site-packages/paraview/selection.py:390, in SelectIDs(IDs, FieldType, ContainingCells, Source, Modifier)
    377 def SelectIDs(IDs=[], FieldType='POINT', ContainingCells=False, Source=None, Modifier=None):
    378 """Select attributes by attribute IDs.
    379
    380 - IDs - list of IDs of attribute types to select. Defined as (process number, attribute ID) pairs
   (...)
    388 should modify the existing selection.
    389 """
--> 390 _selectIDsHelper('IDSelectionSource', **locals())

File ~/Documents/ZooHill/Osprey/osprey-react/dev-tools-env/lib/python3.10/site-packages/paraview/selection.py:330, in _selectIDsHelper(proxyname, IDs, FieldType, ContainingCells, Source, Modifier)
    327 if not Source:
    328 Source = paraview.simple.GetActiveSource()
--> 330 repr = paraview.simple.GetRepresentation(Source)
    332 import paraview.vtk as vtk
    333 reprCollection = vtk.vtkCollection()

File ~/Documents/ZooHill/Osprey/osprey-react/dev-tools-env/lib/python3.10/site-packages/paraview/simple.py:939, in GetRepresentation(proxy, view)
    937 view = active_objects.view
    938 if not view:
--> 939 raise ValueError("view argument cannot be None.")
    940 if not proxy:
    941 proxy = active_objects.source

ValueError: view argument cannot be None.

```

Any pointers would be much appreciated, thanks in advance!

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [November 7, 2024, 2:46pm UTC](https://discourse.paraview.org/t/filtering-by-cell-point-id/15694/2 "2024-11-07T14:46:53Z")

</div>

From what I see, Selection is heavily related to View(s), so you cannot select without a view. So you suggest to create a dummy one (like a Spreadsheet view, that is not so costly) and then you should be able to run your request.

For using ParaView on the web, we have Trame framework ([trame | trame](https://kitware.github.io/trame/)), but this is more a @jourdain question

---

<div class="post-metadata">

### Author: ![Bryce\_Richards](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bryce_richards/32/15514_2.png) [@Bryce\_Richards](https://discourse.paraview.org/u/Bryce_Richards)
#### Post date: [November 7, 2024, 3:57pm UTC](https://discourse.paraview.org/t/filtering-by-cell-point-id/15694/3 "2024-11-07T15:57:55Z")

</div>

Thanks Nicolas. I actually just got this to work with the help of ChatGPT:

```python
import paraview.simple as pvs
from vtkmodules.numpy_interface import dataset_adapter as dsa
...

# This makes a list like [0, id1, 0, id2, 0, id3, ..., 0, idn]. Not sure why it needs to be in this format
point_ids_formatted = list(itertools.chain.from_iterable(zip(itertools.repeat(0), point_ids)))
point_selection = pvs.IDSelectionSource()
point_selection.FieldType = 'POINT'
point_selection.IDs = point_ids_formatted

extracted_points = pvs.ExtractSelection(Input=reader, Selection=point_selection)

data = pvs.servermanager.Fetch(extracted_points)
data_wrapped = dsa.WrapDataObject(data)
num_cells = data_wrapped.GetNumberOfCells()
num_points = data_wrapped.GetNumberOfPoints()

```

This looks like it correctly filters down both the cells and the points. Does this look reasonable to you? Any disadvantage of using this method vs. creating a Spreadsheet view?

Thanks again! Bryce

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [November 7, 2024, 5:13pm UTC](https://discourse.paraview.org/t/filtering-by-cell-point-id/15694/4 "2024-11-07T17:13:33Z")

</div>

Well, if it works …

At least last 4 lines (Fetch and WrapDataObject) are not related to your question.
