create single custom filter in python

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

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

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

You can use a CustomFilter: 11. Advanced: Tips & Tricks — ParaView Documentation 5.12.0 documentation

1 Like

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?

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

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.

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.

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

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

1 Like

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!

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

1 Like

will do, thanks!

1 Like

https://gitlab.kitware.com/paraview/paraview/-/issues/23018