Using a loop python script applied to several *. med file
I want to open , select a specific parameter, apply calculator filter and at last a wrap filter
The main problem lay with the use of appenattibute filter. Indeed in my script, i don’t manage to apply it, to all med files :
import pvsimple
pvsimple.ShowParaviewView()
# trace generated using paraview version 5.9.0
#### import the simple module from the paraview
from pvsimple import *
#### disable automatic camera reset on 'Show'
pvsimple._DisableFirstRenderCameraReset()
a = []
b = [None]
d = [None]
e = [None]
f = [None]
g = [None]
h = [None]
p = [None]
for i in range(3):
# create a new 'MED Reader'
if i < 10:
b.append('rbassin0000%d' % i + 'med')
d.append('rbassin0000%d' % i + 'med' + 'Display')
b[i] = MEDReader(registrationName='rbassin0000' + str(i) + '.med', FileName='/home/vesvard211/maillage/rbassin0000' + str(i) + '.med')
else:
b.append('rbassin0000%d' % i + 'med')
d.append('rbassin000%d' % i + 'med' + 'Display')
b[i] = MEDReader(registrationName='rbassin000' + str(i) + '.med', FileName='/home/vesvard211/maillage/rbassin000' + str(i) + '.med')
# get animation scene
animationScene1 = GetAnimationScene()
# update animation scene based on data timesteps
animationScene1.UpdateAnimationUsingDataTimeSteps()
SetActiveSource(b[i])
# Properties modified on bassin0med
b[i].AllArrays = ['TS0/bassin/ComSup1/Mdepl@@][@@P1']
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# show data in view
d[i] = Show(b[i], renderView1, 'UnstructuredGridRepresentation')
# trace defaults for the display properties.
d[i].Representation = 'Surface'
# reset view to fit data
renderView1.ResetCamera()
# get the material library
materialLibrary1 = GetMaterialLibrary()
# update the view to ensure updated data information
renderView1.Update()
# set scalar coloring
ColorBy(d[i], ('POINTS', 'Mdepl', 'Magnitude'))
# rescale color and/or opacity maps used to include current data range
d[i].RescaleTransferFunctionToDataRange(True, False)
# show color bar/color legend
d[i].SetScalarBarVisibility(renderView1, True)
# get color transfer function/color map for 'Mdepl'
mdeplLUT = GetColorTransferFunction('Mdepl')
# get opacity transfer function/opacity map for 'Mdepl'
mdeplPWF = GetOpacityTransferFunction('Mdepl')
# update the view to ensure updated data information
renderView1.Update()
# set active source
SetActiveSource(print(b[0]))
SetActiveSource(print(b[1]))
SetActiveSource(print(b[2]))
# create a new 'Append Attributes'
appendAttributes1 = AppendAttributes(registrationName='AppendAttributes1', Input=[print(b[i])])
# show data in view
appendAttributes1Display = Show(appendAttributes1, renderView1, 'UnstructuredGridRepresentation')
# trace defaults for the display properties.
appendAttributes1Display.Representation = 'Surface'
for j in range(3):
# create a new 'Calculator'
k = j - 1
e.append("calculator%d" % j)
e[j] = Calculator(registrationName='calculator%d' % j, Input=appendAttributes1)
# Properties modified on calculator1
if j == 0:
e[j].ResultArrayName = 'M%d' % j
e[j].Function = 'Mdepl'
else:
e[j].ResultArrayName = 'M%d' % j
e[j].Function = 'M%d' % k + '+' + 'Mdepl_input_%d' % j
# create a new 'Warp By Vector'
f.append("warpByVector%d" % j)
g.append("warpByVector%d" % j + "Display" )
f[j] = WarpByVector(registrationName="warpByVector%d" % j, Input=[print('calculator%d' % j)])
# Properties modified on warpByVector1
f[j].ScaleFactor = 5000
# show data in view
g[j] = Show(f[j], renderView1, 'UnstructuredGridRepresentation')
# trace defaults for the display properties.
g[j].Representation = 'Surface'
# hide data in view
Hide(b[j], renderView1)
# update the view to ensure updated data information
renderView1.Update()
# set scalar coloring
ColorBy(g[j], ('POINTS', 'M%d' % j, 'Magnitude'))
# rescale color and/or opacity maps used to include current data range
g[j].RescaleTransferFunctionToDataRange(True, False)
# show color bar/color legend
g[j].SetScalarBarVisibility(renderView1, True)
# get color transfer function/color map for 'Mdepl'
mdeplLUT = GetColorTransferFunction('M%d' % j)
# get opacity transfer function/opacity map for 'Mdepl'
mdeplPWF = GetOpacityTransferFunction('M%d' % j)
# Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
mdeplLUT.ApplyPreset('Rainbow Uniform', True)
#### saving camera placements for all active views
# current camera placement for renderView1
renderView1.CameraPosition = [0.007254707374675282, -0.49900709211761174, 0.46427352241737563]
renderView1.CameraFocalPoint = [1.2015019498213393e-06, -6.744833810744443e-08, 0.15000010536583305]
renderView1.CameraViewUp = [0.011771325523215763, 0.5330006202259059, 0.8460329631487336]
renderView1.CameraParallelScale = 0.15264365376518474
see in attach file the screen shot :
question1.pdf (97.4 KB)
regards