Paraview with MED support has been presented previously. This post shows how to run scripts with interactive python console or batch. Thanks to Kirk Morgan for testing and sharing the info !
Monitor the GUI from a Python CMD
Here we show how to monitor ParaView 5.6 with MED with an interactive Python execution. 3 batch files are needed. Each batch loads environment variables and then execute a Paraview program. You may create these file and put at root directory of your Paraview installation.
1. run_pvserver.bat
@ECHO OFF
call "%~dp0\WORK\set_env.bat"
CALL C:\ParaView56\WORK\set_env.bat"
CALL "%PDIR%\env_launch.bat"
pvserver --multi-clients
2. run_paraview.bat
@ECHO OFF
call "%~dp0\WORK\set_env.bat"
CALL "%PDIR%\env_launch.bat"
paraview --server-url=cs://localhost
3. run_pvpython.bat
@ECHO OFF
call "%~dp0\WORK\set_env.bat"
CALL "%PDIR%\env_launch.bat"
pvpython

First you may execute run_pvserver.bat, either by double clicking on it or in a CMD prompt. It will open a Paraview server instance.
Then you may execute run_paraview.bat. It will open a GUI and connect to the server:

Finally execute run_pvsimple.bat. It will open a python console

From the python prompt you can import Paraview commands, connect to the server and execute Paraview commands. Let’s for example open a file:
from paraview.simple import *
Connect("localhost")
pv_object = MEDReader(FileName="linear-static.rmed")
You may notice that the GUI has synchronized and the object file may appear in the treeview:

To go further, you may take a look to paraviw python wiki for more info about what is possible to do with pvsimple. Otherwise you can also dump a study from Salome-Meca:

Save at dump.py

Edit dump.py and get inspiration from what you have done manually in ParaVis:

Run a script with pvbatch
As shown in previous paragraph it is also possible to run directly with pvbath. Let’s create a file run_pvbath.bat
@ECHO OFF
call "%~dp0\WORK\set_env.bat"
CALL "%PDIR%\env_launch.bat"
pvbatch %1
You can execute a script by running run_pvbatch.bat %1 where %1 is filename of script in same directory as .bat files.
Conclusion
You can now use Paraview and have some fun with interactive python, make your own tool and start to automate your work !
One thought on “ParaView MED with pvpython and pvbatch”