The ParaView application is basically a user interface laid on top of the Visualization Toolkit (VTK), which provides the underlying graphics processing. All classes in the VTK have been "wrapped" so that their functionality is accessible to be used in Python scripts. ParaView provides an interactive Python shell that allows you to perform operations on the visualization pipeline by executing Python statements. Outside of ParaView this shell can be launched with the pvpython command. Within ParaView, the shell can be viewed by checking View→Python Shell, which displays the pane:

The initial appearance of ParaView's Python Shell dialog
The initial appearance of ParaView's Python Shell dialog

The paraview Python package that is installed with ParaView contains the wrappers for the VTK functionality. In order to accomplish anything useful with Python in ParaView you would need to execute quite a few VTK Python statements. To alleviate this burden, the paraview package includes a higher level paraview.simple module that more closely resembles the sort of operations that you perform through the ParaView user interface. You can see in the image above that when the Python Shell is launched from ParaView it automatically imports the paraview.simple module. The simple module contains many readers, sources, filters and writers that are well documented.

To begin exploring paraview.simple, perform an Edit→Reset Session, display the Python Shell pane and execute the following three steps in it:

The first of these commands adds a default Sphere source to the visualization pipeline, much as you would get if you used the Sources→Sphere menu option. The method accepts optional parameters to initialize some of its properties. Properties can also be set using the sphere object that the method returns. The second command makes the sphere pipeline node visible. The third command causes the views to be rendered, which in this case causes the sphere to appear for the first time.

The Python Shell dialog after executing some commands
The Python Shell dialog after executing some commands

Depending on what you need to do in the script, you may want to import other Python modules such as the VTK "wrapper" for low level visualization functions:

A useful feature of the Python Shell in ParaView is the ability to load a saved script and execute it. Click the "Run Script" button, then browse to a Python script on the file system. The script will be loaded and immediately executed. This facility can be used to repeatedly execute a series of steps that might be tedious or error prone when performed through the user interface.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement