# writing a pyhon script to semi-automate generation of CSV file for streamlines

**URL:** https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827
**Category:** ParaView Support
**Tags:** python
**Created:** [March 30, 2021, 2:53pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827 "2021-03-30T14:53:14Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![mohammad\_faghih](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mohammad_faghih/32/6098_2.png) [@mohammad\_faghih](https://discourse.paraview.org/u/mohammad_faghih)
#### Post date: [March 30, 2021, 2:53pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/1 "2021-03-30T14:53:14Z")

</div>

I have a couple of simulation cases, that are very similar to each other.  
For all the cases, I need to generate streamlines and export a csv file of the streamline data out for further processing.  
Here is what I would like to be able to do:  
I open one of the cases in paraView, and do all the required steps for generating the desired streamlines, then I save the state file as a python script.  
Now I need to add a snippet (a csv writer of some kind) to the end of this state py file, to save the streamlines spreadsheet.  
The end goal is to be able to use this py code for other cases, by just simply changing the path to the case, to semi-automate things, and write out the csv file without opening paraView.  
Any help is appreciated.

---

<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: [March 30, 2021, 3:02pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/2 "2021-03-30T15:02:10Z")

</div>

> Now I need to add a snippet (a csv writer of some kind) to the end of this state py file, to save the streamlines spreadsheet.

Use `SaveData` method

> The end goal is to be able to use this py code for other cases, by just simply changing the path to the case, to semi-automate things, and write out the csv file without opening paraView.

This is the right way to go.

---

<div class="post-metadata">

### Author: ![mohammad\_faghih](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mohammad_faghih/32/6098_2.png) [@mohammad\_faghih](https://discourse.paraview.org/u/mohammad_faghih)
#### Post date: [March 30, 2021, 3:11pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/3 "2021-03-30T15:11:38Z")

</div>

I added

> SaveData(“sample.csv”)

to the end of my python state file and ran it in pvpython. First it is giving me some errors like this:  
( 22.655s) [paraview] VisRTXBackend.cxx:42 WARN| VisRTX Error: Unsupported device

Also, I don’t know where the file would be saved?

---

<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: [March 30, 2021, 3:15pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/4 "2021-03-30T15:15:42Z")

</div>

> ( 22.655s) [paraview] VisRTXBackend.cxx:42 WARN| VisRTX Error: Unsupported device

You can ignore this warning

> Also, I don’t know where the file would be saved?

In the location you are running your script. Use an absolute path if you want to know.

---

<div class="post-metadata">

### Author: ![mohammad\_faghih](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mohammad_faghih/32/6098_2.png) [@mohammad\_faghih](https://discourse.paraview.org/u/mohammad_faghih)
#### Post date: [March 30, 2021, 3:25pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/5 "2021-03-30T15:25:52Z")

</div>

Here  
[https://docs.paraview.org/en/v5.8/UsersGuide/savingResults.html](https://docs.paraview.org/en/v5.8/UsersGuide/savingResults.html)  
it does not say how or where to specify the path.  
Can you provide more details?

---

<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: [March 30, 2021, 3:27pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/6 "2021-03-30T15:27:59Z")

</div>

`SaveData(“path/to/sample.csv”)`

---

<div class="post-metadata">

### Author: ![mohammad\_faghih](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mohammad_faghih/32/6098_2.png) [@mohammad\_faghih](https://discourse.paraview.org/u/mohammad_faghih)
#### Post date: [March 30, 2021, 3:32pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/7 "2021-03-30T15:32:18Z")

</div>

Unfortunately, it is not saving any data.

---

<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: [March 30, 2021, 3:35pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/8 "2021-03-30T15:35:59Z")

</div>

`SaveData("/home/glow/tmp/file.csv")`

This is working great here.

You probably have an empty source.

---

<div class="post-metadata">

### Author: ![mohammad\_faghih](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mohammad_faghih/32/6098_2.png) [@mohammad\_faghih](https://discourse.paraview.org/u/mohammad_faghih)
#### Post date: [March 30, 2021, 3:40pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/9 "2021-03-30T15:40:28Z")

</div>

When I type it in python prompt within the paraview app, it works;  
but when I add it to the end of the my saved python state file (below SetActiveSource), and run it outside paraview in pvpython, nothing is saved.

---

<div class="post-metadata">

### Author: ![mohammad\_faghih](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mohammad_faghih/32/6098_2.png) [@mohammad\_faghih](https://discourse.paraview.org/u/mohammad_faghih)
#### Post date: [March 30, 2021, 4:46pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/10 "2021-03-30T16:46:50Z")

</div>

can you tell me how I should execute my python state file in pvpython shell?  
right now I am using:

> exec(open(“D:\1\_couetteFLow\stateStreamLine.py”).read())

---

<div class="post-metadata">

### Author: ![mohammad\_faghih](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mohammad_faghih/32/6098_2.png) [@mohammad\_faghih](https://discourse.paraview.org/u/mohammad_faghih)
#### Post date: [March 30, 2021, 5:15pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/11 "2021-03-30T17:15:53Z")

</div>

For future reference, I had to use the following format to get it working:

SaveData(“D:\\1\_couetteFLow\\sample.csv”)

---

<div class="post-metadata">

### Author: ![Sciencegeek](https://discourse.paraview.org/user_avatar/discourse.paraview.org/sciencegeek/32/1609_2.png) [@Sciencegeek](https://discourse.paraview.org/u/Sciencegeek)
#### Post date: [April 4, 2021, 1:04pm UTC](https://discourse.paraview.org/t/writing-a-pyhon-script-to-semi-automate-generation-of-csv-file-for-streamlines/6827/12 "2021-04-04T13:04:53Z")

</div>

Thank you both, I found this conversation interesting **AND** useful. And it occured at the perfect time.  
Again, Thank you,  
Bob
