For the record, I finally found the solution : use ns = globals when loading the plugin ! LoadPlugin ( '/mnt/users/.../libMyFilter.so', remote = False, ns = globals () )

FH

Le 2015-08-18 18:40, houssen a écrit :
Hello,

How to use a plugin from the python script shell prompt ?

I have a plugin (filter) that works fine (manual load with "tools /
manage plugins" + apply filter : OK). I'd like to use python to
manipulate it (to test it actually within "make test").

Here is the python script:
~> more applyFilter.py
#!/usr/bin/env python
from paraview.simple import *
LoadPlugin ( '/mnt/users/.../libMyFilter.so' )
data = XDMFReader ( FileNames = [ '/mnt/users/.../data.xmf' ] )
MyFilter ()

In interactive mode :
1. Make sure I start from scratch : myFilter is not in the "tools /
manage plugins" list.
2. Open a Python shell prompt + run the script.
3. I get this error :
Traceback (most recent call last):
  File "<string>", line 6, in <module>
NameError: name 'MyFilter' is not defined

At this point, I was like "OK, there is perhaps a problem in the
python wrapping of the C++ class". I google a bit and found that :
http://www.cmake.org/pipermail/paraview/2013-December/030229.html. I
tried to modify my plugin CMakeLists.txt (in particular with
pv_setup_module_environment / pv_process_modules from the
EyeDomeLighting plugin example) : didn't succeed to make it work. I
cancelled all related modifications and got back to the initial
CMakeList.txt which contains essentially this :
ADD_PARAVIEW_PLUGIN ( myFilter
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MAJOR}"
SERVER_MANAGER_XML myFilter.xml SERVER_MANAGER_SOURCES myFilter.cpp
DOCUMENTATION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/doc" ).

After that, I was like "OK, maybe I need to import the python module
corresponding to my plugin". As I don't know which one this could be,
I tried to add in the script the line "from paraview.simple import *"
a 2d time after the "LoadPlugin". I get another type of error:
Traceback (most recent call last):
  File "<string>", line 7, in <module>
  File

"/home/houssen/Programs/ParaView/ParaView-v4.3.1-source/local/lib/paraview-4.3/site-packages/paraview/simple.py",
line 1481, in CreateObject
    elif active_objects.source:
  File

"/home/houssen/Programs/ParaView/ParaView-v4.3.1-source/local/lib/paraview-4.3/site-packages/paraview/simple.py",
line 1690, in get_source
    self.__get_selection_model("ActiveSources").GetCurrentProxy())
  File

"/home/houssen/Programs/ParaView/ParaView-v4.3.1-source/local/lib/paraview-4.3/site-packages/paraview/simple.py",
line 1684, in __convert_proxy
    servermanager._getPyProxy(px.GetSourceProxy()),
AttributeError: GetSourceProxy

After some testing, I ended up on this scenario which makes me think
that there is actually no python wrapping problem. Here is the 2d
scenario (in interactive mode):
1. In the GUI use "tools / manage plugins" to load myFilter : OK
2. In the GUI, open a data file
3. Open a Python shell prompt + type only the last script line
"myFilter ()" : this works ?!... Surprisingly ?!
So I would say there is no problem with the python binding.

What did I miss ? Can somebody help me ?

Franck

PS : I run Ubuntu-14.04, I use ParaView-4.3.1 built from source
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at:
http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

Reply via email to