[Paraview] Getting String arrays out of Field Data

Joshua Murphy Joshua.Murphy at lasp.colorado.edu
Thu Sep 6 13:44:41 EDT 2012

Thank you! I was using GetArray(), as I had no idea that
GetAbstractArray() even existed! (tab complete in the Python Shell doesn't
recognize it, and that is how I find most things as I learn how various
things work).

Again, Thank you very much! This solves a big problems for us!


On 9/6/12 11:27 AM, "David Thompson" <david.thompson at kitware.com> wrote:

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