# create single custom filter in python

**URL:** https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916
**Category:** ParaView Support
**Created:** [July 9, 2025, 8:29am UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916 "2025-07-09T08:29:20Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)
#### Post date: [July 9, 2025, 8:29am UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/1 "2025-07-09T08:29:20Z")

</div>

Hello,  
I am creating some small simple functions in python that I will re utilise.  
so for example:

```auto
slice1 = Slice(registrationName='Clip_upperBound_extractFreeSurface', Input=filterForData , 
            Triangulatetheslice = 0,)
slice1.SliceType.Normal = [0.0, 0.0, 1.0]
slice1.SliceType.Origin = [0,0, 0.95*(zMax)]
surfaceNormals3 = SurfaceNormals(registrationName='surfaceNormals3', Input=slice1, ComputeCellNormals=1)
integrateVariablesFlow3 = IntegrateVariables(registrationName='integrateVariablesFlow1', Input=calculatorFlow3,
                                        DivideCellDataByVolume = 0)

```

this will create in the pipeline something like this:  
 ![image](https://discourse.paraview.org/uploads/default/original/3X/c/5/c5486d4efbdbaf0218c161ee82ff3cb1bcb9933a.png)

I would like to instead condensate the three filters into one, or at least that the tree is not collapsed (what the pressing of the ‘-’ on Clip\_upperBound\_extractFreeSurface would do). is this possible (ideally would prefere condensate all to a single filter.)  
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: [July 10, 2025, 7:19am UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/2 "2025-07-10T07:19:19Z")

</div>

You can use a CustomFilter: [11. Advanced: Tips & Tricks — ParaView Documentation 5.12.0 documentation](https://docs.paraview.org/en/latest/Tutorials/ClassroomTutorials/advancedTipsAndTricks.html#creating-a-custom-filter)

---

<div class="post-metadata">

### Author: ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)
#### Post date: [July 10, 2025, 10:51am UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/3 "2025-07-10T10:51:00Z")

</div>

Hello mathieu,  
this is in the gui and i dont see it save it in the trace, what I was looking/asking for, would be similar to this, but define the customFilter inside the python script itself. is this possible?

---

<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: [July 10, 2025, 11:25am UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/4 "2025-07-10T11:25:29Z")

</div>

So you are using pvpython top generate a state that will be loaded in the end in ParaView GUI ?

---

<div class="post-metadata">

### Author: ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)
#### Post date: [July 10, 2025, 11:37am UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/5 "2025-07-10T11:37:43Z")

</div>

I have a base `paraviewFunction.py` file where I created some functions that I use all the time that removes small annoyances of paraview. eg. creating a box using min and max positions instead of the center +dimensions (as it is defined in OpenFOAM). they are ‘stupidly’ simple but it takes time sometimes.

another function i created is `createStreamLinesFromPatch(OFfilter,patchName,regular=False)`  
which basically loads the patch on the OFfilter, extracts the patch (by doing extract block) if regular ==True it create a grid of points by slicing in two directions the extract block, if ==False it uses the points of the patch directly. for finaly create the `streamLineFromCustomSource` filter. for example this function creates at least 2 filters (or 4 if regular==True).

so when i work with paraview i import this `paraviewFunction.py` script so i have acces to all this functions, when I use `createStreamLinesFromPatch` it will create all the different filters in the pipeline which sometimes makes it quite convoluted tree. what I was looking for with the original question (and going back to your fist anwer) is that I define a `customFilter` in the `paraviewFunction.py` script so when I use `createStreamLinesFromPatch` it will create only one filter (a custom filter).  
i want to define it in the `paraviewFunction.py` script (the `customFilter`) so I can port out this script between different pcs, etc, it is my _swiss knife_ for paraview.

---

<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: [July 10, 2025, 11:59am UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/6 "2025-07-10T11:59:42Z")

</div>

Ok, so you have some macros that you can use, but you still use ParaView GUI, which lets you create customer filter, unless I’m misunderstanding something.

---

<div class="post-metadata">

### Author: ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)
#### Post date: [July 10, 2025, 12:09pm UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/7 "2025-07-10T12:09:13Z")

</div>

like macros,  
use my `paraviewFunction.py` in two different ways (a third middle ground).

- scripting  
when I scripting for paraview that I import the file. so there I can pass the correct python objects such as `createStreamLinesFromPatch(openFoamReader,'inlet')`. in this case what I was asking for it does not matter at all as I run the scripts with pvbatch.

- paraview GUI  
I open the python console, select `run script` and run `paraviewFunction.py` and then select in the pipeline the openFoamReader and do `createStreamLinesFromPatch([],'inlet')` (as it has inside the funciton `if openFoamReader==[] then: openFoamReader=GetActiveSource()` ). In this case is where I am looking for and where the pipeline becomes quite unreadable that would prefere to simply have the `customFilter`.

- paraview GUI troubleshooting  
when i finish scripting i generally run the script in the python console just to verify that everything goes smoothly. here as the previous case, it makes quite unredable the pipeline and would like to simplify it.

as I do this in several pcs, i dont want to go thought the gui for create customFilters on each pc as it is quite error prompt, i would like to have it defined inside `paraviewFunction.py`

---

<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: [July 10, 2025, 12:12pm UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/8 "2025-07-10T12:12:30Z")

</div>

Creating custom filters is not supported from pvpython I’m afraid. There are saved in satefiles and can be shared by themselves if needed.

---

<div class="post-metadata">

### Author: ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)
#### Post date: [July 10, 2025, 12:15pm UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/9 "2025-07-10T12:15:52Z")

</div>

okey thanks for your answer and clarification Mathieu, just to finalize do you think of any tool that could do the job of what I am trying to accomplish? or it does not exist? regards!

---

<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: [July 10, 2025, 12:19pm UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/10 "2025-07-10T12:19:38Z")

</div>

Your best bet would be to open an issue in ParaView so that someone actually implements adding custom filter from pvpython 🙂

---

<div class="post-metadata">

### Author: ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)
#### Post date: [July 10, 2025, 12:31pm UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/11 "2025-07-10T12:31:24Z")

</div>

will do, thanks!

---

<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: [July 11, 2025, 9:04am UTC](https://discourse.paraview.org/t/create-single-custom-filter-in-python/16916/12 "2025-07-11T09:04:08Z")

</div>

[https://gitlab.kitware.com/paraview/paraview/-/issues/23018](https://gitlab.kitware.com/paraview/paraview/-/issues/23018)
