3

I am trying to control Paraview interactively using IDLE. This would involve sending commands from IDLE and seeing the changes occur in Paraview. I would rather not use the in-Paraview python shell.

So far, I have succeeded in importing the Paraview modules (simple, servermanager…etc) from IDLE. However the commands sent do not reflect in Paraview. For instance:

>>> from paraview.simple import *
>>> cone = Cone()
>>> Show()
>>> Render()

does indeed create a cone. However the cone is output to a new, independent OpenGL window, and not the Paraview GUI.

Is it possible to control Paraview interactively using IDLE? If so how to accomplish this? Thanks

user32882
  • 5,094
  • 5
  • 43
  • 82
  • IDLE has a special feature that eases development of tkinter applications. It does not do anything special for anything else. For pure interactive control, you should do as well as with interactive Python in a console. (IDLE does add the ability to write and quickly run saved scripts.) I am puzzled that you do not want to use Paraview's console? Have they crippled it? Otherwise, it should be as good as Python or IDLE's shell. – Terry Jan Reedy Jul 21 '17 at 17:37
  • I don't want to use Paraview's console because Paraview is only one of multiple applications I am controlling simultaneously with Python. It wouldn't make sense to centralize my work in Paraview's shell and start coding things that have nothing to do with Paraview. Basically I might be taking data from a python API for another application, processing it using numpy or matlab python engine, and then outputting it for visualization/animation purposes only in Paraview. See Paraview is only one small step in the process. I don't want it to take over my work, which in essence involves other apps – user32882 Jul 22 '17 at 05:09
  • That makes sense, but without knowing Paraview, I cannot comment further. See if you can find a specialized Paraview support list or something. – Terry Jan Reedy Jul 23 '17 at 05:02

2 Answers2

5

You need to run paraview in multiclient/server mode. In a terminal run pvserver.

./bin/pvserver --multi-clients

In another terminal, run paraview and connect to your server

./bin/paraview
File->Connect
AddServer -> Choose a name -> Configure -> Save
Connect

In a third terminal, run pvpython (or your own configured python)

./bin/pvpython
>> from paraview.simple import *
>> Connect("localhost")
>> Cone()
>> Show()
Mathieu Westphal
  • 2,544
  • 1
  • 19
  • 33
  • First of all I think the `Connect(localhost)` should be changed to `Connect("localhost")` to avoid the `NameError: name 'localhost' is not defined` error. secondly when running `Show()` it returns an error `RuntimeError: Show() needs a proxy argument or that an active source is set.` Plus ParaView, opened is non responding after all these. – Foad S. Farimani Sep 07 '18 at 03:31
  • 1
    Indeed, You need to create a source first. I've updated my answer. – Mathieu Westphal Sep 07 '18 at 11:36
  • This is a great way of interacting with paraview! I was wondering if you could add this to [this documentation](https://www.paraview.org/ParaView/Doc/Nightly/www/py-doc/index.html). – Foad S. Farimani Sep 07 '18 at 11:58
  • 1
    This is more relevant to the ParaView guide imo. – Mathieu Westphal Sep 07 '18 at 12:10
0

I built paraview against my system python so that I could use ipython and other packages. I just had to set my PYTHONPATH to point to the paraview python site packages and the LD_LIBRARY_PATH to point to the paraview lib directory.

export PYTHONPATH=/path/to/paraview/install/lib/python2.7/site-packages
export LD_LIBRARY_PATH=/path/to/paraview/install/lib
$ ipython 
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from paraview.simple import *

In [2]: Connect("localhost")
Out[2]: Connection (cs://localhost:11111) [2]

In [3]: Cone()
Out[3]: <paraview.servermanager.Cone at 0x7f30716cde10>

In [4]: Show()
Out[4]: <paraview.servermanager.GeometryRepresentation at 0x7f307167b210>

In [5]: GetSources()
Out[5]: {('Cone1', '8803'): <paraview.servermanager.Cone at 0x7f30716cde10>}

In [6]: GetActiveSource()
Out[6]: <paraview.servermanager.Cone at 0x7f30716cde10>

Screen shot of the rendered cone from the ipython paraview client

My paraview version was built from master on Ubuntu 18.04.

The only issue I had was a missing __init__.py file in the python site-packages/paraview/modules directory.

In [1]: from paraview.simple import *
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-cc11d49fb28b> in <module>()
----> 1 from paraview.simple import *

/home/dustin/repos/paraview_builds/master/install/lib/python2.7/site-packages/paraview/simple.py in <module>()
     39 
     40 import paraview
---> 41 from paraview import servermanager
     42 import paraview._backwardscompatibilityhelper
     43 

/home/dustin/repos/paraview_builds/master/install/lib/python2.7/site-packages/paraview/servermanager.py in <module>()
     54 from paraview import _backwardscompatibilityhelper as _bc
     55 
---> 56 from paraview.modules.vtkPVServerImplementationCore import *
     57 from paraview.modules.vtkPVClientServerCoreCore import *
     58 from paraview.modules.vtkPVServerManagerCore import *

ImportError: No module named modules.vtkPVServerImplementationCore

I got around this by just creating an __init__.py file in the paraview/modules directory:

touch /path/to/paraview/install/lib/python2.7/site-packages/paraview/modules/__init__.py
dustindorroh
  • 311
  • 2
  • 6