[Paraview] Python scripting - displaying results on a FE mesh

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Mon Jun 16 15:08:58 EDT 2008


Here is an example script that color using a point array:

#---------------------------------------------------------------
from paraview import servermanager as sm

sm.Connect()
sphere = sm.sources.SphereSource()
elev = sm.filters.ElevationFilter(Input=sphere)
view = sm.CreateRenderView()
repr = sm.CreateRepresentation(elev, view)

lut = sm.rendering.PVLookupTable()
# Add to RGB points. These are tuples of 4 values. First one is
# the scalar values, the other 3 the RGB values. This list has
# 2 points: Pres: 0.00678, color: blue, Pres: 0.0288, color: red
lut.RGBPoints = [0.0, 0, 0, 1,
                 1.0, 1, 0, 0]
lut.ColorSpace = 1 # HSV

# Color by point array called Elevation
repr.ColorAttributeType = 0 # point data
repr.ColorArrayName = "Elevation"
# Assign it to the representation
repr.LookupTable = lut

view.ResetCamera();
view.StillRender();
#---------------------------------------------------------------

Utkarsh

Robert Cimrman wrote:
> Hi,
> 
> I am trying to write a Python script to visualize a finite element mesh 
> with some fields, stored in a legacy VTK file (unstructured grid). 
> Following Servermanager2.pdf, I have created the script below, which 
> displays the mesh (solid color). However now I do not know how to 
> visualize one of the fields (point data or cell data), i.e. have some 
> colormap and related color bar. Does anyone have a small example script 
> to do that?
> 
> Then I digged more and found:
> http://public.kitware.com/pipermail/paraview/2007-July/005394.html
> The problem is that the script described there, that dumps the session 
> state from the paraview GUI into a python script, does not seem to work 
> with the Paraview 3.2. Is there an updated version somewhere?
> 
> best wishes,
> 
> -- 
> Robert Cimrman
> http://sfepy.org
> 
> -----
> 
> import sys
> from paraview import servermanager
> 
> inFileName = sys.argv[1]
> 
> if not servermanager.ActiveConnection:
>     connection = servermanager.Connect()
> if not connection:
>     raise exceptions.RuntimeError, 'Connection to localhost failed.'
> 
> print inFileName
> 
> reader = servermanager.sources.LegacyVTKFileReader( FileNames = 
> [inFileName] )
> #reader.UpdateVTKObjects()
> #reader.UpdatePipelineInformation()
> print reader
> view = servermanager.CreateRenderView()
> rep = servermanager.CreateRepresentation(reader, view)
> view.StillRender()
> view.ResetCamera()
> view.StillRender()
> 
> raw_input()
> view.WriteImage("image.png", "vtkPNGWriter", 1)
> _______________________________________________
> ParaView mailing list
> ParaView at paraview.org
> http://www.paraview.org/mailman/listinfo/paraview
> 


More information about the ParaView mailing list