7
$\begingroup$

I've been using the basic visualization features of Paraview.

Now, I want to go further by writing python macros to handle some specific tasks.

My question for the advanced users: Are there any known guides to get a proper start ?

Already done:

  • Read the Paraview wiki + found some concise handouts (with which I started)
  • Used "Trace" to record and modify python shell (this is not the best way to learn)
$\endgroup$
2
$\begingroup$

Sorry not quite the answer that you are after...

I have never been able to get the ParaView Python interface to do anything that useful. Though I admit I am only passable at Python and the stuff I want to do is normally outside the box.

I would recommend you get your head around VTK, you will be able to do much much more. Not only are you not restricted by what ParaView gives you Python interface-wise, you will get access to much more VTK features than ParaView exposes. I now tend to test a few things out in ParaView and then jump into VTK once I know what works.

Below is a link to Python examples and a video tut.

VTK Python Code

VTK Python Tut

$\endgroup$
  • $\begingroup$ Although the links contain some interesting stuff, I was looking into more dedicated tutorials. $\endgroup$ – SAAD Sep 15 '13 at 8:59
  • $\begingroup$ Sorry - they are about as good as it gets. I have the book but it is pretty hard going. Unforunately most open source visualisation software relies on trial and error by following examples (either on wikis or in code they use for testing). You can use the Python trace in ParaView and then try and fill the gaps. Do you have an example of what you are trying to achieve? $\endgroup$ – internetscooter Sep 16 '13 at 10:01
  • $\begingroup$ One of the things that I wanted to use is the Reflect command with a user-defined plane, by default Paraview accepts only the predefined planes (X, Y , Z, Xmin, Xmax ...) $\endgroup$ – SAAD Sep 23 '13 at 13:37
  • $\begingroup$ My approach would be to convert this example to Python vtk.org/Wiki/VTK/Examples/Cxx/PolyData/Reflection. The rendering bits are standard, you can steal from another Python example - it is worth leaving them in to debug the result. Hope this helps. $\endgroup$ – internetscooter Sep 24 '13 at 21:02
1
$\begingroup$

I think the most powerful use of python scripting are programmable filters, rather than python shells, since they allow to create objects in the pipeline (and your script will be processed by the server, not the client). You can find some examples in http://www.paraview.org/Wiki/ParaView/Simple_ParaView_3_Python_Filters

If you want to try those script in the python shell, you have just to modify the lines referring to "self" . For example, pdi = self.GetInput() should become something like pdi = servermanager.Fetch(FindSource("sphere1")) . I'm still not sure on the proper way to export data produced in that way (see my temptatives https://stackoverflow.com/a/24273259/1136458 )

You can also save the current state as a python file, instead of pvsm, and check what it has been done there (even if it's not 100% accurate, for example I had problems with some properties of the spreadsheet representation).

If you don't need the rendering, but just load some file, process them and save them, you can have a very quick script: - create your pipeline in paraview GUI
- export state as py
- open the python file and delete all the representation and data visualization code (only if you are not interested in those, of course)
- for exporting a polydata, set it as ActiveSource, then use something like

vtkWriter = DataSetWriter(FileName = 'Surface.vtk' , Input = GetActiveSource(), FileType = 1) 
vtkWriter.UpdatePipeline() 

- run it multiple times just changing some parameters!

As already mentioned by andybauer, you can find the documentation here http://www.paraview.org/ParaView3/Doc/Nightly/www/py-doc/

$\endgroup$
1
$\begingroup$

You may want to use these for reference:

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.