Hi,
I have a working script for generating plots for one file. Now I want to loop over all the files and generate one plot for each of them. Here is the script I am using:
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
import glob
filenames = glob.glob("../data/*.vtu")
for filename in filenames:
# create a new 'XML Unstructured Grid Reader'
testvtu = XMLUnstructuredGridReader(
FileName=[filename])
testvtu.PointArrayStatus = ['B [nT]', 'P [nPa]']
# get active view
view = GetActiveViewOrCreate('RenderView')
# uncomment following to set a specific view size
view.ViewSize = [1352, 754]
# create a new 'Clip'
clip1 = Clip(Input=testvtu)
clip1.ClipType = 'Box'
clip1.ClipType.Position = [-2.0, -2.0, -2.0]
clip1.ClipType.Length = [2.0, 4.0, 4.0]
# create a new 'Contour'
contour1 = Contour(Input=clip1)
contour1.ContourBy = ['POINTS', 'B [nT]_Z']
contour1.Isosurfaces = [0.0]
# show data in view
contour1Display = Show(contour1, view)
# get color transfer function/color map for 'BnT_Z'
pnPaLUT = GetColorTransferFunction('P [nPa]')
# trace defaults for the display properties.
contour1Display.Representation = 'Surface'
contour1Display.ColorArrayName = ['POINTS', 'P [nPa]']
contour1Display.LookupTable = pnPaLUT
contour1Display.OSPRayScaleArray = 'P [nPa]'
contour1Display.OSPRayScaleFunction = 'PiecewiseFunction'
contour1Display.ScaleFactor = 0.4
contour1Display.SelectScaleArray = 'P [nPa]'
contour1Display.GlyphType = 'Arrow'
contour1Display.GlyphTableIndexArray = 'P [nPa]'
contour1Display.GaussianRadius = 0.02
contour1Display.SetScaleArray = ['POINTS', 'P [nPa]']
contour1Display.ScaleTransferFunction = 'PiecewiseFunction'
contour1Display.OpacityArray = ['POINTS', 'P [nPa]']
contour1Display.OpacityTransferFunction = 'PiecewiseFunction'
contour1Display.DataAxesGrid = 'GridAxesRepresentation'
contour1Display.PolarAxes = 'PolarAxesRepresentation'
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
contour1Display.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.1757813367477812e-38, 1.0, 0.5, 0.0]
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
contour1Display.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.1757813367477812e-38, 1.0, 0.5, 0.0]
# show color bar/color legend
contour1Display.SetScalarBarVisibility(view, True)
# rescale color and/or opacity maps used to include current data range
contour1Display.RescaleTransferFunctionToDataRange(True, False)
# show color bar/color legend
contour1Display.SetScalarBarVisibility(view, True)
# get color transfer function/color map for 'PnPa'
pnPaLUT = GetColorTransferFunction('PnPa')
# Properties modified on pnPaLUT
pnPaLUT.AutomaticRescaleRangeMode = 'Never'
# get opacity transfer function/opacity map for 'PnPa'
pnPaPWF = GetOpacityTransferFunction('PnPa')
# Rescale transfer function
pnPaLUT.RescaleTransferFunction(0.01, 10.0)
# Rescale transfer function
pnPaPWF.RescaleTransferFunction(0.01, 10.0)
# Apply a preset using its name.
pnPaLUT.ApplyPreset('Viridis (matplotlib)', True)
# get color legend/bar for pnPaLUT in view
pnPaLUTColorBar = GetScalarBar(pnPaLUT, view)
# change scalar bar placement
pnPaLUTColorBar.WindowLocation = 'AnyLocation'
pnPaLUTColorBar.Position = [0.83, 0.028]
pnPaLUTColorBar.ScalarBarLength = 0.33
# create a new 'Text'
text1 = Text()
tmin = int(filename[21:23])
tsec = int(filename[23:25])
time = tmin*60 + tsec
text1.Text = 't = ' + str(time) + 's'
#text1.Text = filename
text1Display = Show(text1, view)
text1Display.WindowLocation = 'UpperLeftCorner'
text1Display.FontFamily = 'Courier'
text1Display.FontSize = 10
# current camera placement for view
view.CameraPosition = [-6.399978992012728, -0.7675947684358911, 0.007641971283834748]
view.CameraFocalPoint = [3.220738468431737, 0.07902926244000752, 0.007641971283834748]
view.CameraViewUp = [0.0, 0.0, 1.0]
view.CameraParallelScale = 1.384939947024134
# save screenshot
SaveScreenshot(
filename[0:-3]+'png',
view, ImageResolution=[1352, 754])
ResetSession()
However, this gave me some overlapped figures like:
I thought ResetSession() might resolve the problem, but it didn’t. So what am I missing here? Should I avoid creating new Text() and Contour(), and reuse the old ones?
Thanks!