I hope someone can give me some help with this. I’m relatively new to Python programming and plugins/programmable filters in Paraview.
For background, I’m trying to transition from Paraview 5.4.1 to a newer version - I’m targeting 5.11. As part of that process, I’m updating some plugins/programmable filters that were developed one of my colleagues, @DennisConklin, from Python 2 to Python 3.
For the most part, the conversion has gone fairly smoothly, and the process of generating the .xml files is straightforward. However, one of the plugins returns an error I can’t figure out how to fix.
The plugin does some simple calculations on variables from the multiblock exodus dataset it’s applied to and adds the new variables to the output multiblock data set. If the variable being calculated isn’t relevant to one or more blocks (based on the element type in that block), then it prints a message indicating the name of the block and that it’s being skipped.
The calculations are working correctly, the issue is in the generation of that message.
Here’s a stripped down version of the script:
(the calculations have been removed and only the overall structure and get_block_name function remain)
import numpy,vtk
from vtk.numpy_interface import algorithms as algs
from operator import mul
def check_elem_variable_exists(block,variable_name):
keys=block.CellData.keys()
return (variable_name in keys)
def get_block_name(block):
# Get block ID - This is the line that fails
block_id=block.FieldData.GetArray('ElementBlockIds')
output=self.GetOutput()
ElementBlocks=output.GetBlock(0)
block_meta=ElementBlocks.GetMetaData(block_id-1)
block_name=block_meta.Get(vtk.vtkCompositeDataSet.NAME())
return block_name
def hex_ElmCalc(block):
for var in range(numVars):
if not (check_elem_variable_exists(block,arrays[var])):
print(get_block_name(block),"is missing variable",arrays[var])
print("This may cause inaccuracy of the calculation for",arrays[var])
continue
return()
def quad_ElmCalc(block):
for var in range(numVars):
if not (check_elem_variable_exists(block,arrays[var])):
print("Quad block is missing variable",arrays[var])
print("This may cause inaccuracy of the calculation for",arrays[var])
continue
return()
###################################################################
# main routine starts here
output.CopyStructure(inputs[0].VTKObject)
output.DeepCopy(inputs[0].VTKObject)
numVars = arrays.__len__()
print()
for block in output:
# VTK element types:
# 12 = VTK_HEXAHEDRON
# 9 = VTK_QUAD
if block.GetCellType(0)==12:
hex_ElmCalc(block)
if block.GetCellType(0)==9:
quad_ElmCalc(block)
print()
This works properly as a python2 script in Paraview 5.4.1, but it returns the error “TypeError: arguments do not match any overloaded methods” in the newer version (using the same exodus file input).
I’m running Paraview 5.11.1 in Linux (RHEL 7.9).
Please tell me how I need to change the line “block_id=block.FieldData.GetArray(‘ElementBlockIds’)” to get the block id.
(or if there’s a simpler/better way to get the block name)
Thanks