# How to print a list of vertices' location and IDs using python?

**URL:** https://discourse.vtk.org/t/how-to-print-a-list-of-vertices-location-and-ids-using-python/965
**Category:** Support
**Created:** [May 15, 2019, 3:30am UTC](https://discourse.vtk.org/t/how-to-print-a-list-of-vertices-location-and-ids-using-python/965 "2019-05-15T03:30:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Wenye\_He](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wenye_he/32/418_2.png) [@Wenye\_He](https://discourse.vtk.org/u/Wenye_He)
#### Post date: [May 15, 2019, 3:30am UTC](https://discourse.vtk.org/t/how-to-print-a-list-of-vertices-location-and-ids-using-python/965/1 "2019-05-15T03:30:49Z")

</div>

Hello,  
I am new to VTK.  
I want to print a list of vertices’ location and IDs from an imported mesh.  
For a list of vertices, I have to loop “GetPoint(i)”…?  
For a list of IDs, “GetPointIds” return the list of point ids, but how to print the list of IDs.  
What I got is vtkIdList…  
Besides, how to use “PrintSelf”?

---

<div class="post-metadata">

### Author: ![jfavre](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jfavre](https://discourse.vtk.org/u/jfavre)
#### Post date: [May 15, 2019, 1:58pm UTC](https://discourse.vtk.org/t/how-to-print-a-list-of-vertices-location-and-ids-using-python/965/2 "2019-05-15T13:58:38Z")

</div>

It seems like you want a list of ids and coordinates as numpy arrays.  
I would suggest the following:

from vtk.util import numpy\_support  
pd=mesh.GetPointData()  
ida=pd.GetGlobalIds()  
nida=numpy\_support.vtk\_to\_numpy(ida)  
coords = mesh.GetPoints().GetData()  
ncoords = numpy\_support.vtk\_to\_numpy(coords)

ncoords and nida are numpy arrays. easy to view on your terminal.

HTH

---

<div class="post-metadata">

### Author: ![Wenye\_He](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wenye_he/32/418_2.png) [@Wenye\_He](https://discourse.vtk.org/u/Wenye_He)
#### Post date: [May 15, 2019, 2:12pm UTC](https://discourse.vtk.org/t/how-to-print-a-list-of-vertices-location-and-ids-using-python/965/3 "2019-05-15T14:12:56Z")

</div>

I did my work by loops. Thanks for your suggestion. I am doing point2point registration. I modify the arrange and locations of the points in numpy array and replace those of copy of target mesh. Is there any document of numpy\_support for numpy\_to\_vtk?

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [May 15, 2019, 6:30pm UTC](https://discourse.vtk.org/t/how-to-print-a-list-of-vertices-location-and-ids-using-python/965/4 "2019-05-15T18:30:27Z")

</div>

[PyVista](https://docs.pyvista.org) might be a library worth checking out - it creates a streamlined interface to the VTK Python bindings making tasks like this way simpler:

```python
import pyvista as pv
import numpy as np

# Load your file
mesh = pv.read('my_file.vtk')
# Access all the points
print(mesh.points)

```

Also note, we handle all the data conversions between VTK and NumPy for you. These can get complicated depending on your data type

```python
assert isinstance(mesh.points, np.ndarray)

```

For the IDs, we preserve the order of all data from the underlying VTK data object. The IDs would be the index along the 0th axis of the `mesh.points` numpy array:

```python
ids = np.arange(mesh.n_points, dtype=int)
print(ids)

```
