[Paraview] Getting String arrays out of Field Data

David Thompson david.thompson at kitware.com
Thu Sep 6 13:06:47 EDT 2012


Hi Joshua,

> I have written a custom filter for Heliospheric data, and I am placing the model metadata into the Field Data section of ParaView.
> 
> Many of the metadata items are strings. I can view these strings just fine in Spread Sheet view, but anytime I try to get them out of Field Data via python, I get a null value return.  Doubles and Ints return just fine, but I cannot seem to figure out how to get the strings.
> 
> Can someone point me in the right direction for retrieving the strings from Field Data via Python?

What method are you using to get the array from the vtkDataSetAttributes instance that holds the field data? You need to use GetAbstractArray instead of GetArray. Below is a small example that gets string values from cell data on the political.vtp file included in VTKData. If you have an example file with strings in field data, I can take a look at that, too. It should be as simple as replacing the GetCellData() method with GetFieldData().

	David

from vtk import *
rdr = vtkXMLPolyDataReader()
rdr.SetFileName( '/path/to/VTKData/Data/political.vtp' )
rdr.Update();
mesh = rdr.GetOutput()
cd = mesh.GetCellData()
print 'Should have 3 cell data arrays', cd.GetNumberOfArrays()
cd.GetArray(0) # Returns None
sa = cd.GetAbstractArray(0)
print 'Array has %d tuples (should be 980)' % sa.GetNumberOfTuples()
print 'Should be Albania:', sa.GetVariantValue(1).ToString()



More information about the ParaView mailing list