How to extract the value of a field in Python annotation filter

Hello,

Here is what I am trying to do with the Python Annotation filter. in Paraview 5.6.0 (on Ubuntu 20.04)

inputs[0].CellData['myVariable'][0]

The output is:

image

I can see the type of of the output as follows:

type(inputs[0].CellData['myVariable'][0])

The output is:
image

I want to get the value without the parentheses , i.e: 28.724062. But when I try:

inputs[0].CellData['myVariable'][0][0]

or

inputs[0].CellData['myVariable'][0,0]

or

"MyVariable: %6.3f" %(inputs[0].CellData['myVariable'][0])

Paraview hangs, and doesn’t respond without displaying any error message (either on the screen or on the terminal). So I am forced to close it from the terminal.

How can I extract the value of my myVariable without displaying those parentheses?

Thank you



UPDATE:

As a workaround I can do the following:

"My variable: %s" %(str(inputs[0].CellData['myVariable'][0]))

image

But still can’t get rid of the parentheses around the value.

Hi AE3X,

Could you please try “inputs[0].CellData[‘myVariable’].Arrays[0][0]” to firstly get VTKArray from VTKCompositeDataArray? Unfortunately, I don’t have an example with data of <class 'vtkmodules.numpy_interface.dataset_adapter.VTKCompositeDataArray> to check the idea. For the 'vtkmodules.numpy_interface.dataset_adapter.VTKArray> which I have, expression “inputs[0].CellData[0][0]” works fine and my annotation output has no parentheses.

Hope it helps or guide you to other idea.

Best Regards,
Pavel

1 Like