# Select a single cell with pvpython script

**URL:** https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821
**Category:** ParaView Support
**Tags:** python
**Created:** [December 2, 2024, 7:14am UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821 "2024-12-02T07:14:01Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mike518](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@mike518](https://discourse.paraview.org/u/mike518)
#### Post date: [December 2, 2024, 7:14am UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/1 "2024-12-02T07:14:01Z")

</div>

Hi,

I apologise if I have overlooked the solution to this question, but I haven’t found it yet.

In order to determine a quasi steady state, we in the team like to square the speed and have the development over time output. Using pythoncalculator and plotDataOverTime, this takes half a day depending on the results. Therefore, I would like to select only one single cell, as the result of the pythonCalculator is written to all cells.

My example up to the selection looks like this:

```auto
import paraview

from paraview.simple import *

spreadSheetView1 = CreateView('SpreadSheetView')
spreadSheetView1.ColumnToSort = ''
spreadSheetView1.BlockSize = 1024
spreadSheetView1.HiddenColumnLabels = ['Point ID', 'LiquidVel', 'LiquidVel_Magnitude', 'Points', 'Points_Magnitude', 'vtkValidPointMask', 'Block Number']

SetActiveView(None)
layout1 = CreateLayout(name='Layout #1')
SetActiveView(spreadSheetView1)

fluidpvd = PVDReader(registrationName='Fluid.pvd', FileName=pvd_file)
fluidpvd.CellArrays = ['LiquidVel']

pythonCalculator1 = PythonCalculator(registrationName='PythonCalculator1', Input=fluidpvd)
pythonCalculator1.Expression = 'sum(mag(LiquidVel)*mag(LiquidVel))'
pythonCalculator1.ArrayAssociation = 'Cell Data'
pythonCalculator1.ArrayName = 'squaredVelocity'

```

Can someone tell me how to select for example the cell (0,0,0) and plot the squaredVelocity of this one cell over time?

Many thanks in advance!

---

<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: [December 2, 2024, 8:07am UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/2 "2024-12-02T08:07:31Z")

</div>

Hi @mike518

Use `SelectCells` method ?

[https://www.paraview.org/paraview-docs/latest/python/paraview.simple.html#paraview.simple.SelectCells](https://www.paraview.org/paraview-docs/latest/python/paraview.simple.html#paraview.simple.SelectCells)

---

<div class="post-metadata">

### Author: ![mike518](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@mike518](https://discourse.paraview.org/u/mike518)
#### Post date: [December 2, 2024, 8:15am UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/3 "2024-12-02T08:15:35Z")

</div>

Hi @mwestphal

Many thanks for the quick reply Mathieu.

I have already tried a few things with SelectCells, but I don’t understand which parameters I have to enter in the function so that I get the cells 0,0,0 or 1,1,1 and can then use them for plotDataOverTime.

Could you help me with this?

---

<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: [December 2, 2024, 8:18am UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/4 "2024-12-02T08:18:16Z")

</div>

Hum, if you want to select the first cell by id you can do that:

```auto
SelectIDs(IDs=[0], FieldType='CELL')

```

Then PlotSelectionOverTime filter.

---

<div class="post-metadata">

### Author: ![mike518](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@mike518](https://discourse.paraview.org/u/mike518)
#### Post date: [December 2, 2024, 8:20am UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/5 "2024-12-02T08:20:56Z")

</div>

And the input for the PlotSelectionOverTime filter is SelectedIDs or do i have to extractSelection first?

---

<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: [December 2, 2024, 8:24am UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/6 "2024-12-02T08:24:49Z")

</div>

No need to extract selection first.

---

<div class="post-metadata">

### Author: ![mike518](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@mike518](https://discourse.paraview.org/u/mike518)
#### Post date: [December 2, 2024, 8:47am UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/7 "2024-12-02T08:47:22Z")

</div>

I have adapted the code as follows

```auto
fluidpvd = PVDReader(registrationName='Fluid.pvd', FileName=pvd_file)
fluidpvd.CellArrays = ['LiquidVel']

pythonCalculator1 = PythonCalculator(registrationName='PythonCalculator1', Input=fluidpvd)
pythonCalculator1.Expression = 'sum(mag(LiquidVel)*mag(LiquidVel))'
pythonCalculator1.ArrayAssociation = 'Cell Data'
pythonCalculator1.ArrayName = 'squaredVelocity'

SelectIDs(IDs=[0], FieldType='CELL')

plotSelectionOverTime1 = PlotSelectionOverTime(registrationName='PlotSelectionOverTime1', Input=pythonCalculator1, Selection=SelectIDs)

SetActiveView(None)

spreadSheetView3 = CreateView('SpreadSheetView')
spreadSheetView3.ColumnToSort = ''
spreadSheetView3.BlockSize = 1024
layout1 = GetLayoutByName("Layout #1")
AssignViewToLayout(view=spreadSheetView3, layout=layout1, hint=3)

plotSelectionOverTime1Display = Show(plotSelectionOverTime1, spreadSheetView3, 'SpreadSheetRepresentation')

```

and get the following error

```auto
File "/home/SelectCell.py", line 73, in <module>
    plotSelectionOverTime1 = PlotSelectionOverTime(registrationName='PlotSelectionOverTime1', Input=pythonCalculator1, Selection=SelectIDs)
  File "/usr/local/lib/python3.10/site-packages/paraview/simple.py", line 2706, in CreateObject
    SetProperties(px, **params)
  File "/usr/local/lib/python3.10/site-packages/paraview/simple.py", line 851, in SetProperties
    pyproxy. __setattr__ (param, params[param])
  File "/usr/local/lib/python3.10/site-packages/paraview/servermanager.py", line 485, in __setattr__
    setter(self, value)
  File "/usr/local/lib/python3.10/site-packages/paraview/servermanager.py", line 2618, in setProperty
    return self.SetPropertyWithName(propName, value)
  File "/usr/local/lib/python3.10/site-packages/paraview/servermanager.py", line 344, in SetPropertyWithName
    prop.SetData(arg)
  File "/usr/local/lib/python3.10/site-packages/paraview/servermanager.py", line 1467, in SetData
    self.SMProperty.AddInputConnection(value.SMProxy, value.Port)
AttributeError: 'function' object has no attribute 'SMProxy'

```

were line 73 is

```auto
plotSelectionOverTime1 = PlotSelectionOverTime(registrationName='PlotSelectionOverTime1', Input=pythonCalculator1, Selection=SelectIDs)

```

Can you please tell me what i have done wrong?

---

<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: [December 2, 2024, 1:25pm UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/8 "2024-12-02T13:25:06Z")

</div>

This syntax should work:

```auto
QuerySelect(QueryString='(id == 0)', FieldType='CELL', InsideOut=0)
PlotSelectionOverTime()
CreateLayout()
CreateView('XYChartView')
AssignViewToLayout()
Show()

```

---

<div class="post-metadata">

### Author: ![mike518](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@mike518](https://discourse.paraview.org/u/mike518)
#### Post date: [December 4, 2024, 12:58pm UTC](https://discourse.paraview.org/t/select-a-single-cell-with-pvpython-script/15821/9 "2024-12-04T12:58:26Z")

</div>

It worked, thank you very much!
