# Adding a new attribute (data array )

**URL:** https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258
**Category:** ParaView Support
**Tags:** python
**Created:** [June 29, 2018, 3:50pm UTC](https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258 "2018-06-29T15:50:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jrojaspa](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@jrojaspa](https://discourse.paraview.org/u/jrojaspa)
#### Post date: [June 29, 2018, 3:50pm UTC](https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258/1 "2018-06-29T15:50:41Z")

</div>

Hi all,  
(Paraview V 4.3.1 )

I am trying to add a new Attribute (data array of scalar values) associated to the points of a Delaunay Mesh I have in Paraview. I would like that once it is selected from the GUI, it would show the associated colors and the range of values bar.

I have tried using the methods: .GetPointData().AddArray(array) and other methods available online, which did not work for me.

I would really appreciate if you could help me with this subject.

Thanks in advance for your help!

Juan

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [July 9, 2018, 4:11am UTC](https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258/2 "2018-07-09T04:11:24Z")

</div>

Hello

First I would suggest upgrading to ParaView 5.5 if possible.  
It is not clear where you want to add the array ? in a VTK C++ code ? In this case do not forget to set a name to your array.

---

<div class="post-metadata">

### Author: ![jrojaspa](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@jrojaspa](https://discourse.paraview.org/u/jrojaspa)
#### Post date: [July 9, 2018, 6:58am UTC](https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258/3 "2018-07-09T06:58:19Z")

</div>

Hi Mathieu,

Thanks for your answer. I was able to finally install the V. 5.5.2.

I have a mesh of type: multiblock dataset, and I want to add the array by using pvpython in Paraview. I have noticed that it is possible to create these arrays by using the programmable filter. I checked the examples here, and also the associated links:

[https://www.paraview.org/Wiki/Python\_Programmable\_Filter](https://www.paraview.org/Wiki/Python_Programmable_Filter)

However, I haven’t been able to create the array of scalars I want because the information I have found so far is mainly for meshes which are not multiblock dataset. From the mesh I have I would like to do:

pdo.GetPointData().SetScalars(vals1) like in the example of the helix:  
[https://www.paraview.org/Wiki/ParaView/Simple\_ParaView\_3\_Python\_Filters](https://www.paraview.org/Wiki/ParaView/Simple_ParaView_3_Python_Filters)

However, this methods work for non multiblock datasets,

Thanks,  
Juan

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [July 9, 2018, 7:01am UTC](https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258/4 "2018-07-09T07:01:46Z")

</div>

Where do vals come from ? Can you share your multiblock dataset ?

---

<div class="post-metadata">

### Author: ![jrojaspa](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@jrojaspa](https://discourse.paraview.org/u/jrojaspa)
#### Post date: [July 9, 2018, 7:17am UTC](https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258/5 "2018-07-09T07:17:02Z")

</div>

Vals1 comme from an array of scalars (type: vtk.vtkDoubleArray()) I calculate using pvpython.

No, I can’t, but here is the specific mesh type I work with:

vtkCommonDataModelPython.vtkMultiBlockDataSet

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [July 9, 2018, 7:26am UTC](https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258/6 "2018-07-09T07:26:46Z")

</div>

Ok.

You should indeed use a Python Programmable Filter, iterate over your multiblock dataset, and add your vals in each leaf dataset.

```
iter = mb.NewTreeIterator()
iter.VisitOnlyLeavesOn()
iter.SkipEmptyNodesOn()
while not iter.IsDoneWithTraversal():
  obj = iter.GetCurrentDataObject()
  pd = obj.GetPointData()
  pd->AddArray(namedArrayWithTheRightNumberOfTuples)
  iter.GoToNextItem()
```

---

<div class="post-metadata">

### Author: ![jrojaspa](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@jrojaspa](https://discourse.paraview.org/u/jrojaspa)
#### Post date: [July 9, 2018, 8:12am UTC](https://discourse.paraview.org/t/adding-a-new-attribute-data-array/258/7 "2018-07-09T08:12:28Z")

</div>

Thank you so much!

The code worked just fine 🙂
