# How to run a python macro with paraFoam?

**URL:** https://discourse.paraview.org/t/how-to-run-a-python-macro-with-parafoam/17530
**Category:** ParaView Support
**Tags:** python
**Created:** [April 21, 2026, 8:02pm UTC](https://discourse.paraview.org/t/how-to-run-a-python-macro-with-parafoam/17530 "2026-04-21T20:02:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Faraz\_Hussain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/faraz_hussain/32/17608_2.png) [@Faraz\_Hussain](https://discourse.paraview.org/u/Faraz_Hussain)
#### Post date: [April 21, 2026, 8:02pm UTC](https://discourse.paraview.org/t/how-to-run-a-python-macro-with-parafoam/17530/1 "2026-04-21T20:02:21Z")

</div>

I created a simple macro to automate some post processing. It works if I launch paraFoam and click the button for it in the GUI. But I want to run this without having to “click the button”. Here’s what I tried along with the error messages. Guessing I need to manually edit the paraFoam script?

```auto
[fhussa@lgn001 0.5_conical]$ touch 0.5_conical.foam
[fhussa@lgn001 0.5_conical]$ pvpython movie.py
Traceback (most recent call last):
  File "/data/users/fhussa/openfoam/0.5_conical/movie.py", line 15, in <module>
    a02_conicalfoam.CaseType = 'Decomposed Case'
AttributeError: 'NoneType' object has no attribute 'CaseType'

[fhussa@lgn001 0.5_conical]$ paraview --script movie.py
Traceback (most recent call last):
  File "<string>", line 15, in <module>
AttributeError: 'NoneType' object has no attribute 'CaseType'

[fhussa@lgn001 0.5_conical]$ paraFoam --script movie.py
Invalid $PV_PLUGIN_PATH and -plugin-path= not defined
No supplementary ParaView/OpenFOAM reader modules
Using builtin reader: paraFoam -vtk

--script excludes --data
Usage: paraview [OPTIONS] 

[General Guidelines] 

Values for options can be specified either with a space (' ') or an equal-to sign ('='). Thus, '--option=value' and '--option value' are equivalent. 

Multi-valued options can be specified by providing the option multiple times or separating the values by a comma (','). Thus, '--moption=foo,bar' and '--moption=foo --moption=bar' are equivalent. 

Short-named options with more than one character name are no longer supported, and should simply be specified as long-named option by adding an additional '-'. Thus, use '--dr' instead of '-dr'. 

Some options are described in this help text with the format '--moption TYPE:name' where 'TYPE' specifies what kind of value is expected for the option 'name'. Type 'ENUM' means there are several possible predefined values for the option. Type 'TEXT' means that the filename option is any text string. 

Numeric specifiers 'INT' and 'FLOAT' in this help text indicate the expected option value type of some options, either an integer or floating point number. 

 
Try `--help` for more more information.
[fhussa@lgn001 0.5_conical]$

```

---

<div class="post-metadata">

### Author: ![Faraz\_Hussain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/faraz_hussain/32/17608_2.png) [@Faraz\_Hussain](https://discourse.paraview.org/u/Faraz_Hussain)
#### Post date: [April 21, 2026, 8:49pm UTC](https://discourse.paraview.org/t/how-to-run-a-python-macro-with-parafoam/17530/2 "2026-04-21T20:49:55Z")

</div>

Think I got it working. I first copied the paraFoam script to the folder where my project is. I edited the third last line at the bottom as follows:

Code:

```auto
paraview --script my_macro.py 2>&1 \

```

Then in my\_macro.py I add this at the top after the import line:

Code:

```auto
from paraview.simple import *
reader = OpenDataFile("my_project.foam")

```

Then from command line I run:

Code:

```auto
./paraFoam

```

Seems to work ok!

Also worked as follows:

Code:

```auto
touch my_project.foam
paraview --script automate.py

```

and:

Code:

```auto
touch my_project.foam
pvpython automate.py

```
