Is there any way to use vtkPythonAlgorithmBase Filters WITHOUT pv.LoadPlugin?

Hi,

First of all, thank you to all the ParaView developers for making this fantastic product! Our team has been using ParaView for serious visualisation tasks in production.

In our use case, we are writing ParaView Python Script to automate the everyday visualisation and analysis works.
In some complex tasks, we need to implement custom filters - for example, calculating momentum on the specified surfaces, annotating the images with the upper/lower bound of the specified data, etc.

Originally, we used ProgrammableFilters to implement such filters. But it becomes quickly tedious to maintain Python scripts that contain ProgrammableFilters, as they accept Python code as a string. The problems are that we cannot apply IDE features directly to those input and we cannot reuse them from other programs.

Fortunately, we found a very nice mechanism for it - vtkPythonAlgorithmBase approach. This works quite nicely, as we can implement custom filters as a real Python script, and we can load it as a custom plugin from ParaView the GUI App.

But here is the question: is there any ways to load vtkPythonAlgorighmBase-based filters WITHOUT resorting to paraview.simple.LoadPlugin?
More specifically, I have the following questions:

  1. Is there any way to use plugins defined in the same file as the ParaView Python Script being executed? In other words, is there any way to use locally-defined vtkPythonAlgorithmBase filters?

  2. Is it possible to use Python import statement to load external vtkPythonAlgorithmBase filters? Currently, we need to use a dirty hack something like:

    # Load Custom Filters
    SCPT_DIR = Path(__file__).parent
    plugin_path = SCPT_DIR / "custom_filters.py"
    
    pv.LoadPlugin(str(plugin_path), remote=True)
    

Thank you in advance,

1 Like

Hi @konn

Welcome and Thanks for the kind words!

Is there any way to use plugins defined in the same file as the ParaView Python Script being executed?
Is it possible to use Python import statement to load external vtkPythonAlgorithmBase filters?

I’m afraid there is nothing more than the hack you are using, that being said I think this is a usecase that woul make sense to support more cleanly>

Another way to look at it is to use generic plugin automatic loading capabilities. You could rely on PV_PLUGIN_PATH and other similar mechanism to load the plugin. See here for the doc:
https://www.paraview.org/Wiki/ParaView/Plugin_HowTo#Using_Plugins

You would be able to load your plugin with:

PV_PLUGIN_PATH=/path/to/dir paraview

Sadly the doc is outdated a bit, needs to be ported to the new docs.

1 Like

Hi @mwestphal,

Thank you for your quick reply!

I’m afraid there is nothing more than the hack you are using, that being said I think this is a usecase that woul make sense to support more cleanly

Thank you for your information. Yes, it would be great to have such a mechanism!

Another way to look at it is to use generic plugin automatic loading capabilities. You could rely on PV_PLUGIN_PATH and other similar mechanism to load the plugin. See here for the doc:
https://www.paraview.org/Wiki/ParaView/Plugin_HowTo#Using_Plugins

You would be able to load your plugin with:

PV_PLUGIN_PATH=/path/to/dir paraview

Thank you for pointing it out! It seems a good tentative workaround for the time being. Concerning the security, it might be still good to have a mechanism to load locally-defined filters and/or specified filters by import, as it gives finer-grained control. Is there any possibility that such a feature gets implemented anytime soon?

1 Like

PV_PLUGIN_CONFIG_FILE let you point a json file allowing for a finer grain.

That being said, I do thing improving the LoadPlugin method to be able to find plugin easily, eg in the local dir, would be a great addition, but that would require funding or contribution.

1 Like

Aha, that makes more sense!

Got it. I think the workarounds you pointed out works fine for the time being, but when we really need more improvements, we will consider that direction :+1: Thank you for your kind replies and suggestions!