There are two ways to start scripting in ParaView, one is the hard way of starting from scratch which teaches us the nitty gritty details of ParaView along the way. The other is the faster approach that we follow here of modifying an auto generated python code. This approach is preferred if we only need to make small modifications to the code generated. Lets begin by opening ParaView from the terminal. Its better at this stage to open ParaView without passing any arguments:

paraview 

As the GUI window pops up, navigate to the View tab and select the Start Trace option. A window opens up with some options describing the amount of Trace code to be generated. For our purposes, Trace only changes will be sufficient. Click on Show Incremental Trace. Now we are all set to let ParaView record our steps as a code. Proceed to the workflow as usual, and all major changes will occasionally be reflected in the trace editor. Once all the actions in the workflow pipeline have been done, delete all the pipeline stages starting from the last one. This generates corresponding lines of delete code in the Trace editor. Save the final Trace file in a python file format (.py). You can now close the ParaView window. We will henceforth work on this file (lets call this file trace.py).

Before we move on to editing this file to suit our purpose, we will check the generated python file. There are two ways to check this:

  1. Open ParaView. Go to the Python Shell tab and enable it. This opens a Python Shell. Click on run scripts in the Python Shell window, navigate to the folder where the data and the Python Trace file is kept, and load it. This runs the entire code from the Trace file. A point to note down, since we have added lines for delete command as well, we will momentariy see the output window before it gets deleted. But if this works, it ensures that the generated script is working.
  2. The other way of opening the script is through pvpython, a non-GUI ParaView binary which can be found at the same location as the paraview binary. To run the file just execute the following code in the command line:
    pvpython trace.py 
    

    This again will momentarily show the ParaView GUI before the code exits.

Moving Forward

This tutorial verifies that we have a working auto generated python code, and how to run it. Now lets delve into some modifications to this trace.py file to get more out of ParaView.