[Paraview] How to use a filter in a Python script?

m.c.wilkins at massey.ac.nz m.c.wilkins at massey.ac.nz
Wed Nov 3 17:27:05 EDT 2010


Hi,

Yes the trace is great, it still couldn't tell me how to actually
extract the numbers along a plotoverline though, without doing a
Spreadsheet view or something.

You have probably figured out how to do a plotoverline using the Trace:

from paraview.simple import *
reader = servermanager.sources.XMLUnstructuredGridReader(FileName = "/var/tmp/file.vtu")
pl = PlotOverLine(Input = reader)
pl.Source.Point1 = [-7000, -5000, 0]
pl.Source.Point2 = [4300, 6300, 1111.75]
CreateXYPlotView()
d = Show()
d.XArrayName = 'arc_length'
d.SeriesVisibility = ['namecolours (0)', '0', 'namecolours (1)', '0', 'namecolours (2)', '0', 'vtkValidPointMask', '0', 'arc_length', '0'] # whatever your variables are
d.UseIndexForXAxis = 0
Render()

But to actually get the values out you don't even need to do the plot
a simple:

from paraview.simple import *
reader = servermanager.sources.XMLUnstructuredGridReader(FileName = "/var/tmp/file.vtu")
pl = PlotOverLine(Input = reader)
pl.Source.Point1 = [-7000, -5000, 0]
pl.Source.Point2 = [4300, 6300, 1111.75]

does, followed by stuff like this:

# to get the number of points on the plotoverline line
pl = servermanager.Fetch(pl)
pl.GetPoints().GetData().GetNumberOfPoints()

# to get the (x,y,z) info for the points on the pol line
pl.GetPoints().GetData().GetValue(0) -> x of first point
pl.GetPoints().GetData().GetValue(1) -> y of first point
pl.GetPoints().GetData().GetValue(2) -> z of first point
etc

# to get the data on the line
pl.GetPointData().GetArray(0).GetValue(0)
etc

# and to get the name of the array on the line
pl.GetPointData().GetArrayName(0) -> 'cfnode'
etc

Matt Wilkins

On Wed, Nov 03, 2010 at 11:38:25AM -0400, ghw at accutrol.com wrote:
> Dude!  You are sooooo awesome!  Why didn't I think of that?  Because 
> I thought trace was for something altogether different from that.  
> 
> Now I feel like I can do anything!
> 
> Thanks immensely for your help,
> Hamilton Woods
> 
> 
> ---------- Original Message -----------
> From: emonson at cs.duke.edu
> To: ghw at accutrol.com
> Cc: paraview list <paraview at paraview.org>
> Sent: Wed, 3 Nov 2010 11:20:47 -0400
> Subject: Re: [Paraview] How to use a filter in a Python script?
> 
> > Hey Hamilton,
> > 
> > You should also try using the Python Trace (and Trace State) 
> > functionality now built into ParaView. After (or while) you set up 
> > your pipeline in ParaView this will give you a Python script to 
> > accomplish the same thing. This page tells a bit about the current 
> > (git) version:
> > 
> > http://www.paraview.org/Wiki/Python_GUI_Tools
> > 
> > You'll see the Start Trace and Trace State if you go to Tools-
> > >Python Shell, and then click on the Trace tab on the right of the panel.
> > 
> > -Eric
> > 
> > ------------------------------------------------------
> > Eric E Monson
> > Duke Visualization Technology Group
> > 
> > On Nov 3, 2010, at 10:00 AM, Sebastien Jourdain wrote:
> > 
> > > Hi Hamilton,
> > > 
> > > You can look at http://www.paraview.org/Wiki/ParaView/Python_Scripting
> > > and that http://www.paraview.org/Wiki/ParaViewUsersGuide/List_of_filters
> > > 
> > > Seb
> > > 
> > > On Tue, Nov 2, 2010 at 10:31 PM,  <ghw at accutrol.com> wrote:
> > >> I am a newbie to Paraview and have little experience programming Python.  I
> > >> would like to know how to call a particular filter from within Python.  The
> > >> only filter I have seen referenced in the Python scripting documentation is
> > >> Shrink().
> > >> 
> > >> I want to retrieve the scalar values along a line segment (Plot Over
> > >> Line(ProbeLine)) that extends through an unstructured 3D grid.  I have "The
> > >> ParaView Guide", "The VTK User's Guide" and "The Visualization Toolkit:  An
> > >> Object-Oriented Approach to 3D Graphics".  I don't see how to
> programmatically
> > >> do this.  I have looked on all of the ParaView web sites that I can find, and
> > >> in tutorials.  I do not even see a list of available filter names.
> > >> 
> > >> Is there a guide for Python Scripting (chapter 20 of The ParaView Guide
> is the
> > >> best I have found) that covers using filters?  Example code?  Anything?  How
> > >> do you even find the filter names in the documentation?
> > >> 
> > >> Thanks for any help,
> > >> Hamilton Woods
> > >> _______________________________________________
> > >> Powered by www.kitware.com
> > >> 
> > >> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> > >> 
> > >> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
> > >> 
> > >> Follow this link to subscribe/unsubscribe:
> > >> http://www.paraview.org/mailman/listinfo/paraview
> > >> 
> > > _______________________________________________
> > > Powered by www.kitware.com
> > > 
> > > Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> > > 
> > > Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
> > > 
> > > Follow this link to subscribe/unsubscribe:
> > > http://www.paraview.org/mailman/listinfo/paraview
> ------- End of Original Message -------
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView
> 
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview


More information about the ParaView mailing list