# vtkXMLPolyDataReader get data per each Piece

**URL:** https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943
**Category:** ParaView Support
**Tags:** vtk
**Created:** [June 29, 2022, 5:34pm UTC](https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943 "2022-06-29T17:34:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![CapLek](https://discourse.paraview.org/user_avatar/discourse.paraview.org/caplek/32/3430_2.png) [@CapLek](https://discourse.paraview.org/u/CapLek)
#### Post date: [June 29, 2022, 5:34pm UTC](https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943/1 "2022-06-29T17:34:22Z")

</div>

I have a VTP file with some number of Pieces in it, representing separate geometry regions. What I want to do is to assign a separate actor for each Piece to be able to differentiate them using picker in Paraview Shell script. There’s a reader in vtkmodules called vtkXMLPolyDataReader which has a property GetNumberOfPieces returning correct number of pieces in VTP file after reading.

The question is how to extract the data belonging to a particular Piece?

_reader = vtkXMLPolyDataReader()_  
_reader.SetFileName(filePath)_  
_reader.Update()_  
_mapper = vtkPolyDataMapper()_  
_mapper.SetInputData(put here code to extract data for i-th piece)_

---

<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: [June 30, 2022, 8:28am UTC](https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943/2 "2022-06-30T08:28:49Z")

</div>

Hi @CapLek ,

Is this a ParaView question or VTK question ?

Best,

---

<div class="post-metadata">

### Author: ![CapLek](https://discourse.paraview.org/user_avatar/discourse.paraview.org/caplek/32/3430_2.png) [@CapLek](https://discourse.paraview.org/u/CapLek)
#### Post date: [June 30, 2022, 10:03am UTC](https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943/3 "2022-06-30T10:03:41Z")

</div>

Hi Mathieu,

This is VTK inside Paraview Python Shell question. I know there is a VTK specific forum but I`m sure this is a better place to ask. Because mentioned reader and overall approach should work inside Paraview.

Thanks, Oleh

---

<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: [June 30, 2022, 11:46am UTC](https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943/4 "2022-06-30T11:46:55Z")

</div>

VTK inside ParaView Python Sheel is not supposed.

In any case, what you want to do is not possible with ParaView, you need to separate your data. Maybe the Connectivity filter works for you.

---

<div class="post-metadata">

### Author: ![CapLek](https://discourse.paraview.org/user_avatar/discourse.paraview.org/caplek/32/3430_2.png) [@CapLek](https://discourse.paraview.org/u/CapLek)
#### Post date: [June 30, 2022, 1:02pm UTC](https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943/5 "2022-06-30T13:02:17Z")

</div>

If it is not supposed, why is it available through the API?

Let’s imagine that this is the VTK question under Python API. How can I get geometry data for separate piece from the VTP file red using vtkXMLPolyDataReader?

Thanks, Oleh

---

<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: [June 30, 2022, 1:06pm UTC](https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943/6 "2022-06-30T13:06:11Z")

</div>

> If it is not supposed, why is it available through the API?

It is not available unless you import VTK specifically.

> Let’s imagine that this is the VTK question under Python API. How can I get geometry data for separate piece from the VTP file red using vtkXMLPolyDataReader?

Is your dataset separated in pieces ?  
If that is the case, use UpdatePiece:

[https://vtk.org/doc/nightly/html/classvtkAlgorithm.html#a3646e9bc4a9c088879adb82060f19c17](https://vtk.org/doc/nightly/html/classvtkAlgorithm.html#a3646e9bc4a9c088879adb82060f19c17)

---

<div class="post-metadata">

### Author: ![CapLek](https://discourse.paraview.org/user_avatar/discourse.paraview.org/caplek/32/3430_2.png) [@CapLek](https://discourse.paraview.org/u/CapLek)
#### Post date: [June 30, 2022, 1:48pm UTC](https://discourse.paraview.org/t/vtkxmlpolydatareader-get-data-per-each-piece/9943/7 "2022-06-30T13:48:54Z")

</div>

Mathieu, thank you very much for the help! It worked!
