# Updating mesh and point data using python

**URL:** https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075
**Category:** ParaView Support
**Tags:** python
**Created:** [April 15, 2020, 2:22pm UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075 "2020-04-15T14:22:04Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Zetison](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/76d3ee/32.png) [@Zetison](https://discourse.paraview.org/u/Zetison)
#### Post date: [April 15, 2020, 2:22pm UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/1 "2020-04-15T14:22:04Z")

</div>

I have a python program that updates the mesh and point data based on user input (sliders in matplotlib.widgets). Is it possible to write and update the paraview.servermanager object directly instead of writing to a file and then reading the same file back into the same paraview object?

Something like (if “a” is an InputProperty object):  
# U is the displacement field  
# p is the pressure field  
# X is the nodes of an structured mesh  
a.SetData(U,p,X)  
a.\_UpdateProperty()

Is this the correct approach, if so, how do I use the SetData() function in this regards? I can create a MWE if desirable.

---

<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: [April 16, 2020, 3:21am UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/2 "2020-04-16T03:21:40Z")

</div>

> [@Zetison](#):
>
> I have a python program that updates the mesh

What do you mean by that ? is “the mesh” a vtkDataSet ?

---

<div class="post-metadata">

### Author: ![Zetison](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/76d3ee/32.png) [@Zetison](https://discourse.paraview.org/u/Zetison)
#### Post date: [April 16, 2020, 7:39am UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/3 "2020-04-16T07:39:05Z")

</div>

The mesh is simply described by a vector of points X, alongside the dimensions of the structured mesh. The program is a Navier-Stokes solver.

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [April 16, 2020, 8:45am UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/4 "2020-04-16T08:45:09Z")

</div>

You can use the `GetClientSideObject()` mechanism. _(this does not work if you use a separate pvserver)_

```python
# create a reader proxy
pv_data = OpenDataFile('myFile')  
# force the data to be loaded
pv_data.UpdatePipeline() 
# get the vtk reader behind the paraview object
vtk_reader = pv_data.GetClientSideObject() 
# get the vtkDataObject produced by the reader
vtk_data = vtk_reader.GetOutput()

```

Then you may modify `vtk_data` on the fly.  
To set data in pv object:

```python
vtk_reader.SetOutput(myNewVTKData)

```

Note that this output may be overwritten by an update of the filter so you may want to put your data in a `PVTrivialProducer` as pv\_data.

---

<div class="post-metadata">

### Author: ![Zetison](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/76d3ee/32.png) [@Zetison](https://discourse.paraview.org/u/Zetison)
#### Post date: [April 27, 2020, 7:21am UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/5 "2020-04-27T07:21:04Z")

</div>

Do you have to create a new VTK object in this approach instead of updating a given array? In any case, I’m not sure how to get and update a given field in a VTK object. I can get i.e. the range for an array ‘U’ in the following manner:

```
obj = XMLUnstructuredGridReader(FileName=['myFile'])
obj.PointData.GetArray("U").GetRange()

```

it would be convenient if I could just set and get values for that array along the lines of the following

```
Uvalues = obj.PointData.GetArray("U").GetValues()
obj.PointData.GetArray("U").SetValues(Uvalues)
```

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [April 27, 2020, 9:29am UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/6 "2020-04-27T09:29:26Z")

</div>

You cannot set values from this object.  
`PointData.GetArray()` returns an `ArrayInformation` and not the data itself. You really need the `GetClientSideObject()`. Note that it does not create a vtk object but only access one already existing in memory

---

<div class="post-metadata">

### Author: ![Zetison](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/76d3ee/32.png) [@Zetison](https://discourse.paraview.org/u/Zetison)
#### Post date: [April 27, 2020, 7:25pm UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/7 "2020-04-27T19:25:05Z")

</div>

Ok. But how exactly do I use the GetClientSideObject() function for the example outlined above? How to convert from and to a numpy array?

---

<div class="post-metadata">

### Author: ![gangyi\_rao](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gangyi_rao/32/6038_2.png) [@gangyi\_rao](https://discourse.paraview.org/u/gangyi_rao)
#### Post date: [March 3, 2021, 1:44pm UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/8 "2021-03-03T13:44:19Z")

</div>

Hi Zetison,  
Do you have implement this feature? I just want to update the PointData value in vtkMultiBlockDataSet and refresh the colormap of paraview.  
Do you have a good solution? Does any experts can help me?

Thanks.

---

<div class="post-metadata">

### Author: ![gangyi\_rao](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gangyi_rao/32/6038_2.png) [@gangyi\_rao](https://discourse.paraview.org/u/gangyi_rao)
#### Post date: [March 3, 2021, 2:05pm UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/9 "2021-03-03T14:05:47Z")

</div>

Hi Nicolas,  
My soure object is a multiblockObject. I get the ClientSideObject, and then I update the PointData of sub block of the multiblockObject. And then copy a new multiblockObject to setOutput(). But I find that paraview have no change.  
The code is like this:

```auto
 vtkSMSourceProxy* soureProxy = m_pqSource->getSourceProxy();
 vtkObjectBase* objBase = soureProxy->GetClientSideObject();
 vtkFileSeriesReader* fileReader = vtkFileSeriesReader::SafeDownCast(objBase);
 vtkMultiBlockDataSet* newDataSet = vtkMultiBlockDataSet::New();
 newDataSet->DeepCopy(m_multiBlockDataSet);
 fileReader->SetOutput(newDataSet);

```

I have updated the vtkDataArray value in the PointData of the m\_multiBlockDataSet.  
Dose something else I need to do?

Thanks

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [March 11, 2021, 8:42am UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/10 "2021-03-11T08:42:07Z")

</div>

Hi,

ParaView (and VTK) are based on a pipeline infrastructure (see [more](https://docs.paraview.org/en/latest/UsersGuide/introduction.html#basics-of-visualization-in-paraview) in the [docs](https://docs.paraview.org/en/latest/UsersGuide/filteringData.html) ). Each element (reader and filter) can be automatically recomputed as needed, so manually setting the output as you did is not a viable solution: it will certainly be overriden.

To set your own data in the pipeline, use the `PVTrivialProducer`.

---

<div class="post-metadata">

### Author: ![gangyi\_rao](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gangyi_rao/32/6038_2.png) [@gangyi\_rao](https://discourse.paraview.org/u/gangyi_rao)
#### Post date: [March 14, 2021, 12:51pm UTC](https://discourse.paraview.org/t/updating-mesh-and-point-data-using-python/4075/11 "2021-03-14T12:51:23Z")

</div>

Hi Nicolas,  
Yeah, I got it. thank you. Now I use the file as the input. If I want to display different field in the pointdata.I just can switch to openning different file. It can work, but it has a little ineffective.
