# Reveal underlying codes when executing commands in the paraView GUI

**URL:** https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878
**Category:** Development
**Tags:** python
**Created:** [August 27, 2021, 10:58am UTC](https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878 "2021-08-27T10:58:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![massisenergy](https://discourse.paraview.org/user_avatar/discourse.paraview.org/massisenergy/32/6229_2.png) [@massisenergy](https://discourse.paraview.org/u/massisenergy)
#### Post date: [August 27, 2021, 10:58am UTC](https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878/1 "2021-08-27T10:58:36Z")

</div>

This is probably a noob question, but not unlikely from a inexperienced python/ParaView/C++ programmer & user of ParaView –

I would like to automate some stuffs (python or C++ scripting?) but dunno how to start since I’m new to scripting. Take the example case:

1. Need to run my custom programmable filter to generate a spreadsheet with data, &
2. Export do disk, such `.csv`s at each timepoint automatically.

I am able to work though the first goal, with this link – [https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html#adding-a-new-point-cell-data-array-based-on-an-input-array](https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html#adding-a-new-point-cell-data-array-based-on-an-input-array)

Content of my Programmable filter:

```auto
input0=inputs[0]

#Calcualtion
volCell=volume(input0)
#volCellP=input0.CellData["volCell"]*volFracP
volFracP=input0.CellData["kinematicCloudTheta"]*1000
volCellP=volCell*volFracP
vol1P=4/3*22/7*((5e-6)**3)
numPCell=volCellP/vol1P

# add to output
output.CellData.append(volFracP, 'volFracP')
output.CellData.append(volCellP, 'volCellP')
output.CellData.append(numPCell, 'numPCell')

```

For the second goal, I went to: [https://www.paraview.org/Wiki/ParaView/Users\_Guide/List\_of\_writers#CSVWriter](https://www.paraview.org/Wiki/ParaView/Users_Guide/List_of_writers#CSVWriter), but not sure where to add this & how to execute. I was wondering, I might be able to follow the underlying codes that are running if I can somehow make ParaView show the commands when e.g. I click on the export button on the generated spreadsheet & then adapt into a script. In longterm, that can be useful in learning scripting while working with different modules.

Anyone has any suggestion?

---

<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: [August 27, 2021, 1:08pm UTC](https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878/2 "2021-08-27T13:08:31Z")

</div>

You are looking for python scripting. You can generate your python script by using Tools → Start Trace.

---

<div class="post-metadata">

### Author: ![massisenergy](https://discourse.paraview.org/user_avatar/discourse.paraview.org/massisenergy/32/6229_2.png) [@massisenergy](https://discourse.paraview.org/u/massisenergy)
#### Post date: [August 27, 2021, 1:47pm UTC](https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878/3 "2021-08-27T13:47:29Z")

</div>

Thanks! My bad, found that’s mentioned here: [https://docs.paraview.org/en/v5.8/UsersGuide/introduction.html?highlight=pvpython#tracing-actions-for-scripting](https://docs.paraview.org/en/v5.8/UsersGuide/introduction.html?highlight=pvpython#tracing-actions-for-scripting).

---

<div class="post-metadata">

### Author: ![massisenergy](https://discourse.paraview.org/user_avatar/discourse.paraview.org/massisenergy/32/6229_2.png) [@massisenergy](https://discourse.paraview.org/u/massisenergy)
#### Post date: [August 27, 2021, 1:49pm UTC](https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878/4 "2021-08-27T13:49:47Z")

</div>

Oh, but this ain’t simple copy-paste, as it results in error:

```auto
>>> # get animation scene
animationScene1 = GetAnimationScene()
# Properties modified on animationScene1
animationScene1.AnimationTime = 1.0
# get the time-keeper
timeKeeper1 = GetTimeKeeper()
# export view
ExportView('/Users/massisenergy/Downloads/22GBQC_particleFoam_mT250duration_pPS2500_T10sec.csv', view=spreadSheetView1, RealNumberNotation='Mixed',
RealNumberPrecision=8)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'spreadSheetView1' is not defined
>>> 

```

---

<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: [August 27, 2021, 2:00pm UTC](https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878/5 "2021-08-27T14:00:00Z")

</div>

well,

```auto
spreadSheetView1=GetActiveView

```

should fix it

---

<div class="post-metadata">

### Author: ![massisenergy](https://discourse.paraview.org/user_avatar/discourse.paraview.org/massisenergy/32/6229_2.png) [@massisenergy](https://discourse.paraview.org/u/massisenergy)
#### Post date: [August 27, 2021, 3:24pm UTC](https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878/6 "2021-08-27T15:24:31Z")

</div>

Solved, thanks to @mwestphal, and @mohammad_faghih for this post discussion: [https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827).

For future reference, I am already using paraView in remoteServer-localClient mode, there are two ways to do it:

1. **Exported into local client disk:**

Use GUI menu option `view` \> `Python Shell`, run the code below:

```auto
>>> # get animation scene
animationScene1 = GetAnimationScene()

# Properties modified on animationScene1
animationScene1.AnimationTime = 9.0

# get the time-keeper and the active view
timeKeeper1 = GetTimeKeeper()
spreadSheetView1=GetActiveView()
# export view
ExportView('/Users/massisenergy/Downloads/22GBQC_particleFoam_mT250duration_pPS2500_T10sec.csv', view=spreadSheetView1, RealNumberNotation='Mixed',
    RealNumberPrecision=8)
>>> # get animation scene
animationScene1 = GetAnimationScene()
# Properties modified on animationScene1
animationScene1.AnimationTime = 9.0
# get the time-keeper 
timeKeeper1 = GetTimeKeeper()
# get the active view
spreadSheetView1=GetActiveView()
# export view
ExportView('/Users/massisenergy/Downloads/22GBQC_particleFoam_mT250duration_pPS2500_T9sec.csv', view=spreadSheetView1, RealNumberNotation='Mixed',
    RealNumberPrecision=8)

```

the resulting `.csv` file will be for single time step and written in the specified local directory.

1. **Exported into remote server disk:**

- this can be revealed done via the GUI like this: Select the data in the GUI to be exported, in my case, `ProgrammableFilter1` \> `File` \> `Save Data (⌘S)` \> Choose csv \> `CSVWriter` pops up.

- the reproducible way is to use the Trace tool mentioned before, from where the code can be copy-pasted into the Python Shell & fine-tuned more:

```auto
# save data
SaveData('/home/massisenergy/autoMount/Data_Documents/Dox_ownCloud/openFoamDataSR/E3DBP_Nozzle/ResTimeDistribution/22G_blunted/22GBQuarterCyl_simpleFoam/22GBQC_particleFoam/VTK_22GBQC_particleFoam_mT250duration_pPS2500/22GBQC_particleFoam_mT250duration_pPS2500.csv', proxy=programmableFilter1, WriteTimeSteps=1,
    Filenamesuffix='_%d',
    ChooseArraysToWrite=0,
    PointDataArrays=[],
    CellDataArrays=['U', 'cellID', 'kinematicCloudTheta', 'numPCell', 'shearStress', 'volCellP', 'volFracP'],
    FieldDataArrays=[],
    VertexDataArrays=[],
    EdgeDataArrays=[],
    RowDataArrays=[],
    Precision=5,
    UseScientificNotation=1,
    FieldAssociation='Cell Data',
    AddMetaData=1,
    AddTime=1)

```

Documentation for saving data is here: [https://docs.paraview.org/en/v5.8/UsersGuide/savingResults.html#saving-datasets](https://docs.paraview.org/en/v5.8/UsersGuide/savingResults.html#saving-datasets)  
This saves my fingers from 3or4 clicks each for 60 time-steps 😂

The code with description can be found here: [particleFraction\_numPCell\_sSMag\_UMag.ProgrammableFilter\_script](https://gitlab.com/massisenergy/paraview_scripts/-/blob/main/particleFraction_numPCell_sSMag_UMag.ProgrammableFilter_script)

---

<div class="post-metadata">

### Author: ![massisenergy](https://discourse.paraview.org/user_avatar/discourse.paraview.org/massisenergy/32/6229_2.png) [@massisenergy](https://discourse.paraview.org/u/massisenergy)
#### Post date: [September 18, 2021, 5:06pm UTC](https://discourse.paraview.org/t/reveal-underlying-codes-when-executing-commands-in-the-paraview-gui/7878/7 "2021-09-18T17:06:21Z")

</div>

For the people coming here in future, another handy tips from Jean Favre of CSCS:

- `File` \> `Save State` **save as “.py”** , not as _“.pvsm”_
- Easily understand the code in human friendly python.
