Hi everyone - I am trying to generate a Python script that can automate the following Paraview file conversion/smoothing pipeline (using Paraview version 5.11.2):
(1) Read in an Exodus (.e) or VTK (.vtu) file into Paraview,
(2) Apply Cell Data to Point Data
filter,
(3) Apply Iso Volume
filter, with lower bound = 0.95 and upper bound = 2 (something above 1),
(4) Apply Extract Surface
filter and save as an STL (ASCII) file.
I’ve generated a Python script by simply opening Paraview, and going into Tools
>> Start Trace
, and then executing the steps above, and then clicking Tools
>> Stop Trace
once I’m finished. This generates a Python script which should in theory be capable of executing the above steps automatically, without needing to manually open the Paraview GUI. However, when I attempt to do this with an Exodus file called 3d_mbb_out.e
(i.e. this is an outputted file when running TopOpt via MOOSE on the input file 3d_mbb.i
located here), my resulting Python script is incapable of saving a smoothed STL file called 3dmbb.stl
. The script I generated is seen below:
# trace generated using paraview version 5.11.2
#import paraview
#paraview.compatibility.major = 5
#paraview.compatibility.minor = 11
#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'IOSS Reader'
a3d_mbb_oute = IOSSReader(registrationName='3d_mbb_out.e', FileName=['/home/enk001/Documents/PHD/PHD-Code/projects-MOOSE/moose/modules/combined/examples/optimization/3d_mbb_out.e'])
a3d_mbb_oute.ElementBlocks = ['block_0']
a3d_mbb_oute.NodeBlockFields = ['Dc', 'disp', 'mat_den_nodal', 'sensitivity']
a3d_mbb_oute.ElementBlockFields = ['Dc_elem', 'E0', 'Emin', 'mat_den', 'power']
a3d_mbb_oute.NodeSets = ['back', 'bottom', 'right', 'top', 'left', 'front', 'hold_y', 'push']
a3d_mbb_oute.SideSets = ['back', 'bottom', 'right', 'top', 'left', 'front']
# get animation scene
animationScene1 = GetAnimationScene()
# get the time-keeper
timeKeeper1 = GetTimeKeeper()
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# get display properties
a3d_mbb_outeDisplay = GetDisplayProperties(a3d_mbb_oute, view=renderView1)
# get color transfer function/color map for 'vtkBlockColors'
vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
# get opacity transfer function/opacity map for 'vtkBlockColors'
vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
# get 2D transfer function for 'vtkBlockColors'
vtkBlockColorsTF2D = GetTransferFunction2D('vtkBlockColors')
# update animation scene based on data timesteps
animationScene1.UpdateAnimationUsingDataTimeSteps()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.ElementBlockFields = ['Dc_elem', 'E0', 'Emin', 'mat_den']
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.ElementBlockFields = ['Dc_elem', 'E0', 'mat_den']
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.ElementBlockFields = ['Dc_elem', 'mat_den']
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.ElementBlockFields = ['mat_den']
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.NodeBlockFields = ['Dc', 'disp', 'mat_den_nodal']
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.NodeBlockFields = ['Dc', 'disp']
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.NodeBlockFields = ['Dc']
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.NodeBlockFields = []
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on a3d_mbb_oute
a3d_mbb_oute.ApplyDisplacements = 0
# update the view to ensure updated data information
renderView1.Update()
# set scalar coloring
ColorBy(a3d_mbb_outeDisplay, ('CELLS', 'mat_den'))
# Hide the scalar bar for this color map if no visible data is colored by it.
HideScalarBarIfNotNeeded(vtkBlockColorsLUT, renderView1)
# rescale color and/or opacity maps used to include current data range
a3d_mbb_outeDisplay.RescaleTransferFunctionToDataRange(True, False)
# show color bar/color legend
a3d_mbb_outeDisplay.SetScalarBarVisibility(renderView1, True)
# get color transfer function/color map for 'mat_den'
mat_denLUT = GetColorTransferFunction('mat_den')
# get opacity transfer function/opacity map for 'mat_den'
mat_denPWF = GetOpacityTransferFunction('mat_den')
# get 2D transfer function for 'mat_den'
mat_denTF2D = GetTransferFunction2D('mat_den')
# create a new 'Cell Data to Point Data'
cellDatatoPointData1 = CellDatatoPointData(registrationName='CellDatatoPointData1', Input=a3d_mbb_oute)
cellDatatoPointData1.CellDataArraytoprocess = ['element_side', 'ids', 'mat_den', 'object_id']
# show data in view
cellDatatoPointData1Display = Show(cellDatatoPointData1, renderView1, 'UnstructuredGridRepresentation')
# trace defaults for the display properties.
cellDatatoPointData1Display.Representation = 'Surface'
cellDatatoPointData1Display.ColorArrayName = [None, '']
cellDatatoPointData1Display.SelectTCoordArray = 'None'
cellDatatoPointData1Display.SelectNormalArray = 'None'
cellDatatoPointData1Display.SelectTangentArray = 'None'
cellDatatoPointData1Display.OSPRayScaleArray = 'element_side'
cellDatatoPointData1Display.OSPRayScaleFunction = 'PiecewiseFunction'
cellDatatoPointData1Display.SelectOrientationVectors = 'None'
cellDatatoPointData1Display.ScaleFactor = 3.0
cellDatatoPointData1Display.SelectScaleArray = 'None'
cellDatatoPointData1Display.GlyphType = 'Arrow'
cellDatatoPointData1Display.GlyphTableIndexArray = 'None'
cellDatatoPointData1Display.GaussianRadius = 0.15
cellDatatoPointData1Display.SetScaleArray = ['POINTS', 'element_side']
cellDatatoPointData1Display.ScaleTransferFunction = 'PiecewiseFunction'
cellDatatoPointData1Display.OpacityArray = ['POINTS', 'element_side']
cellDatatoPointData1Display.OpacityTransferFunction = 'PiecewiseFunction'
cellDatatoPointData1Display.DataAxesGrid = 'GridAxesRepresentation'
cellDatatoPointData1Display.PolarAxes = 'PolarAxesRepresentation'
cellDatatoPointData1Display.ScalarOpacityUnitDistance = 1.008114241552259
cellDatatoPointData1Display.OpacityArrayName = ['POINTS', 'element_side']
cellDatatoPointData1Display.SelectInputVectors = [None, '']
cellDatatoPointData1Display.WriteLog = ''
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
cellDatatoPointData1Display.ScaleTransferFunction.Points = [1.0, 0.0, 0.5, 0.0, 24000.0, 1.0, 0.5, 0.0]
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
cellDatatoPointData1Display.OpacityTransferFunction.Points = [1.0, 0.0, 0.5, 0.0, 24000.0, 1.0, 0.5, 0.0]
# hide data in view
Hide(a3d_mbb_oute, renderView1)
# update the view to ensure updated data information
renderView1.Update()
# set scalar coloring
ColorBy(cellDatatoPointData1Display, ('FIELD', 'vtkBlockColors'))
# show color bar/color legend
cellDatatoPointData1Display.SetScalarBarVisibility(renderView1, True)
# set scalar coloring
ColorBy(cellDatatoPointData1Display, ('POINTS', 'mat_den'))
# Hide the scalar bar for this color map if no visible data is colored by it.
HideScalarBarIfNotNeeded(vtkBlockColorsLUT, renderView1)
# rescale color and/or opacity maps used to include current data range
cellDatatoPointData1Display.RescaleTransferFunctionToDataRange(True, False)
# show color bar/color legend
cellDatatoPointData1Display.SetScalarBarVisibility(renderView1, True)
# create a new 'Iso Volume'
isoVolume1 = IsoVolume(registrationName='IsoVolume1', Input=cellDatatoPointData1)
isoVolume1.InputScalars = ['POINTS', 'mat_den']
isoVolume1.ThresholdRange = [8.614340690391311e-09, 1.0]
# show data in view
isoVolume1Display = Show(isoVolume1, renderView1, 'UnstructuredGridRepresentation')
# trace defaults for the display properties.
isoVolume1Display.Representation = 'Surface'
isoVolume1Display.ColorArrayName = ['POINTS', 'mat_den']
isoVolume1Display.LookupTable = mat_denLUT
isoVolume1Display.SelectTCoordArray = 'None'
isoVolume1Display.SelectNormalArray = 'None'
isoVolume1Display.SelectTangentArray = 'None'
isoVolume1Display.OSPRayScaleArray = 'mat_den'
isoVolume1Display.OSPRayScaleFunction = 'PiecewiseFunction'
isoVolume1Display.SelectOrientationVectors = 'None'
isoVolume1Display.ScaleFactor = 3.0
isoVolume1Display.SelectScaleArray = 'mat_den'
isoVolume1Display.GlyphType = 'Arrow'
isoVolume1Display.GlyphTableIndexArray = 'mat_den'
isoVolume1Display.GaussianRadius = 0.15
isoVolume1Display.SetScaleArray = ['POINTS', 'mat_den']
isoVolume1Display.ScaleTransferFunction = 'PiecewiseFunction'
isoVolume1Display.OpacityArray = ['POINTS', 'mat_den']
isoVolume1Display.OpacityTransferFunction = 'PiecewiseFunction'
isoVolume1Display.DataAxesGrid = 'GridAxesRepresentation'
isoVolume1Display.PolarAxes = 'PolarAxesRepresentation'
isoVolume1Display.ScalarOpacityFunction = mat_denPWF
isoVolume1Display.ScalarOpacityUnitDistance = 1.1167665609818371
isoVolume1Display.OpacityArrayName = ['POINTS', 'mat_den']
isoVolume1Display.SelectInputVectors = [None, '']
isoVolume1Display.WriteLog = ''
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
isoVolume1Display.ScaleTransferFunction.Points = [8.614340690391311e-09, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
isoVolume1Display.OpacityTransferFunction.Points = [8.614340690391311e-09, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
# hide data in view
Hide(cellDatatoPointData1, renderView1)
# show color bar/color legend
isoVolume1Display.SetScalarBarVisibility(renderView1, True)
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on isoVolume1
isoVolume1.ThresholdRange = [8.614340690391311e-09, 2.0]
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on isoVolume1
isoVolume1.ThresholdRange = [0.95, 2.0]
# update the view to ensure updated data information
renderView1.Update()
# create a new 'Extract Surface'
extractSurface1 = ExtractSurface(registrationName='ExtractSurface1', Input=isoVolume1)
# show data in view
extractSurface1Display = Show(extractSurface1, renderView1, 'GeometryRepresentation')
# trace defaults for the display properties.
extractSurface1Display.Representation = 'Surface'
extractSurface1Display.ColorArrayName = ['POINTS', 'mat_den']
extractSurface1Display.LookupTable = mat_denLUT
extractSurface1Display.SelectTCoordArray = 'None'
extractSurface1Display.SelectNormalArray = 'None'
extractSurface1Display.SelectTangentArray = 'None'
extractSurface1Display.OSPRayScaleArray = 'mat_den'
extractSurface1Display.OSPRayScaleFunction = 'PiecewiseFunction'
extractSurface1Display.SelectOrientationVectors = 'None'
extractSurface1Display.ScaleFactor = 3.0
extractSurface1Display.SelectScaleArray = 'mat_den'
extractSurface1Display.GlyphType = 'Arrow'
extractSurface1Display.GlyphTableIndexArray = 'mat_den'
extractSurface1Display.GaussianRadius = 0.15
extractSurface1Display.SetScaleArray = ['POINTS', 'mat_den']
extractSurface1Display.ScaleTransferFunction = 'PiecewiseFunction'
extractSurface1Display.OpacityArray = ['POINTS', 'mat_den']
extractSurface1Display.OpacityTransferFunction = 'PiecewiseFunction'
extractSurface1Display.DataAxesGrid = 'GridAxesRepresentation'
extractSurface1Display.PolarAxes = 'PolarAxesRepresentation'
extractSurface1Display.SelectInputVectors = [None, '']
extractSurface1Display.WriteLog = ''
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
extractSurface1Display.ScaleTransferFunction.Points = [0.95, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
extractSurface1Display.OpacityTransferFunction.Points = [0.95, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
# hide data in view
Hide(isoVolume1, renderView1)
# show color bar/color legend
extractSurface1Display.SetScalarBarVisibility(renderView1, True)
# update the view to ensure updated data information
renderView1.Update()
# save data
SaveData('/home/enk001/Documents/PHD/PHD-Code/projects-MOOSE/moose/modules/combined/examples/optimization/3dmbb.stl', proxy=extractSurface1, PointDataArrays=['mat_den'],
FieldDataArrays=['Information Records', 'QA Records', 'total_vol'],
FileType='Ascii')
When I run this script, I get the following output/error messages:
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.336s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5b79bdc0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.430s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c4732f0): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
( 1.441s) [paraview ]vtkTableBasedClipDataSe:214 ERR| vtkPVClipDataSet (0x571e5c47bb40): no input scalars.
Has anyone been able to generate a Python script of the file conversion/smoothing pipeline that successfully writes a smoothed STL file (ASCII)? To be clear, when I execute the above file conversion pipeline in the Paraview GUI, I get the above error messages, but an STL file is still written successfully despite the error messages. However, using my Python script, I cannot write a smoothed STL file.