[Paraview] Getting String arrays out of Field Data

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

Hi Joshua,

Sorry, in my previous e-mail I forgot this was the ParaView and not VTK mailing list, so I posted a vtkpython script. What I said still applies if you are using the Python Programmable Filter, but of course you can use ParaView to load the dataset.

pdi = self.GetPolyDataInput()
pdo =  self.GetPolyDataOutput()
print s.GetVariantValue(1).ToString()
# Just copy the input to make ParaView happy:
pdo.DeepCopy( pdi )

This works for me with the political.vtp dataset


Does that address your problem? Or are you writing client-side python scripts using the simple interface to retrieve metadata from the server?


>> 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