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()
s=pdi.GetCellData().GetAbstractArray(0)
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

  http://vtk.org/gitweb?p=VTKData.git;a=blob_plain;f=Data/political.vtp;hb=HEAD


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

_______________________________________________
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

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to