I have just updated from Paraview 4.3.1 to 5.1.0 and am having trouble with a 
Python script that no longer works correctly.

The attached script cycles through exodus files in a given directory, and for 
each file plots a surface plot of GlobalElementId overlain with a threshold 
plot of 2 other cell variables (one after the other), producing a screenshot of 
each image. This was working just fine with v4.3.1, but when I run it in 5.1.0 
it fails to plot  GlobalElementId except for the first file, and fails to show 
the scalar color bar for any of the files. What has gone wrong?

Regards.
Heather
########## Enter information here ############################################
#### File path and naming convention
path = '/aPath/'
file_start = 'blah_'
file_end = '.e'

#### Camera position
CamPosition = [9872.882259982869, 13839.720442049857, 69246.67738888811]
CamFocalPoint = [9872.882259982869, 13839.720442049857, -5410.87158203125]
CamParallelScale = 28839.4075588125

#### Image size
view_size = [722,1092]

#### Scalar bar position and orientation
sbar_bottom_left = [0.05,0.01] # relative position of bottom left corner of scalar bar
sbar_top_right = [0.85,0.06] # relative position of top right corner of scalar bar
sbar_orientation = "Horizontal"

#### List the block names in the exodus file
blocks = ['block1','block2']

#### Name of variable to use for background
background_var = 'GlobalElementId'

#### Make a dictionary for each variable you want to visualise
# 'name' is the name of the variable in the exodus file
# 'title' is the title for the color bar
# 'threshold' is a list containing the min and max threshold values
# 'color_range' is a list containing the min and max values for the scalar color bar
vsi_dict = {'name':'vol_strain',
			'title':'Vol strain',
			'threshold':[0.01,100.0],
			'color_range':[0.01,0.03]
			}
tensfail_dict = {'name':'tens_fail',
			'title':'Tensile failure',
			'threshold':[0.00001,100.0],
			'color_range':[0.0,0.01]
			}
			
#### List all dictionaries here
all_vars = [vsi_dict,tensfail_dict]
###############################################################################

import os

#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

# Clean up any existing views (necessary if using GUI)
RemoveViewsAndLayouts()

element_vars = []
for dict in all_vars: element_vars.append(dict['name'])

for afile in os.listdir(path):
	if afile.startswith(file_start) and afile.endswith(file_end):	
		print 'Processing file %s' % afile		
		afile = os.path.join(path,afile)
		dict = all_vars[0]

		# create a new 'ExodusIIReader'
		reader = ExodusIIReader(FileName=[afile])
		reader.ElementVariables = element_vars
		reader.PointVariables = []
		reader.GlobalVariables = []
		reader.NodeSetArrayStatus = []
		reader.SideSetArrayStatus = []
		reader.ElementBlocks = blocks

		# get animation scene
		animationScene1 = GetAnimationScene()

		# update animation scene based on data timesteps
		animationScene1.UpdateAnimationUsingDataTimeSteps()
		animationScene1.GoToLast()

		# get active view
		renderView1 = CreateRenderView()
		renderView1.ViewSize = view_size
		renderView1.OrientationAxesVisibility = 0

		# current camera placement for renderView1
		renderView1.CameraPosition = CamPosition
		renderView1.CameraFocalPoint = CamFocalPoint
		renderView1.CameraParallelScale = CamParallelScale
		
		# show data in view
		backgroundDisplay = Show(reader, renderView1)
		
		# trace defaults for the display properties.
		backgroundDisplay.AmbientColor = [0.0, 0.0, 0.0]
		backgroundDisplay.ColorArrayName = [None, '']

		# set scalar coloring
		ColorBy(backgroundDisplay, ('CELLS', background_var))

		# rescale color and/or opacity maps used to include current data range
		backgroundDisplay.RescaleTransferFunctionToDataRange(True)

		# get color transfer function/color map for background_var
		backgroundLUT = GetColorTransferFunction(background_var)
		# change the color map to Grayscale
		#backgroundLUT.ApplyPreset('Grayscale', True)

		# Set opacity
		backgroundDisplay.Opacity = 0.1
		
		# hide color bar/color legend for background
		b_bar = GetScalarBar(backgroundLUT,renderView1)
		b_bar.Visibility = False

		for dict in all_vars:
			# get color transfer function/color map
			aLUT = GetColorTransferFunction('dummy')
			# Rescale transfer function
			aLUT.RescaleTransferFunction(dict['color_range'][0], dict['color_range'][1])

			# get opacity transfer function/opacity map
			aPWF = GetOpacityTransferFunction('dummy')
			# Rescale transfer function
			aPWF.RescaleTransferFunction(dict['color_range'][0], dict['color_range'][1])

			# create a new 'Threshold'
			threshold1 = Threshold(Input=reader)
			threshold1.Scalars = ['CELLS', dict['name']]
			threshold1.ThresholdRange = dict['threshold']

			# show data in view
			threshold1Display = Show(threshold1, renderView1)
			# trace defaults for the display properties.
			threshold1Display.ColorArrayName = ['CELLS', dict['name']]
			threshold1Display.LookupTable = aLUT
			bar = GetScalarBar(aLUT,renderView1)
			bar.Title = dict['title']
			bar.ComponentTitle = ''
			bar.Position = sbar_bottom_left 
			bar.Position2 = sbar_top_right 
			bar.Orientation = sbar_orientation
			bar.Visibility = True
	
			# save screenshot
			image_file = afile.replace('.e','background_%s.png' % dict['name'])
			SaveScreenshot(image_file, magnification=1, quality=100, view=renderView1)

			# destroy threshold1
			Delete(threshold1)
			del threshold1

		# destroy reader and render view
		Delete(reader)
		del reader
		Delete(renderView1)
		del renderView1
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

Reply via email to