# vtk-9.2.5 python wrapper vtkProp3DCollection.GetNextProp3D() return null

**URL:** https://discourse.vtk.org/t/vtk-9-2-5-python-wrapper-vtkprop3dcollection-getnextprop3d-return-null/10504
**Category:** Support
**Tags:** training, python, code
**Created:** [January 19, 2023, 2:37pm UTC](https://discourse.vtk.org/t/vtk-9-2-5-python-wrapper-vtkprop3dcollection-getnextprop3d-return-null/10504 "2023-01-19T14:37:07Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![TartaPise](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/47e85d/32.png) [@TartaPise](https://discourse.vtk.org/u/TartaPise)
#### Post date: [January 19, 2023, 2:37pm UTC](https://discourse.vtk.org/t/vtk-9-2-5-python-wrapper-vtkprop3dcollection-getnextprop3d-return-null/10504/1 "2023-01-19T14:37:07Z")

</div>

Hello everyone, I’m new to the Forum, please treat me well and let me know if I do something wrong.

I’m having issues writing a simple python function to save the centers of the actors in a vtkassembly.

Here is the function:  
def get\_spheres\_centers(assembly):  
print(assembly)  
collection=vtk.vtkProp3DCollection()  
assembly.GetActors(collection)  
print(collection)

```
for i in range(collection.GetNumberOfItems()):
    actor=collection.GetNextProp3D()
    print(actor)
    centers[i-1,:]=actor.GetCenter()
return centers

```

GetNextProp3D() always returns NULL, i’ve tried using  
actor=collection.GetLastProp3D()  
and this work but of course always return the last actor of the collection. Any idea why?

---

<div class="post-metadata">

### Author: ![TartaPise](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/47e85d/32.png) [@TartaPise](https://discourse.vtk.org/u/TartaPise)
#### Post date: [January 19, 2023, 2:42pm UTC](https://discourse.vtk.org/t/vtk-9-2-5-python-wrapper-vtkprop3dcollection-getnextprop3d-return-null/10504/2 "2023-01-19T14:42:01Z")

</div>

I’m so dumb sorry. I just needed to initialize the position inside the collection. I’ll leave here the solution just in case anyone else look for this:

def get\_spheres\_centers(assembly):  
collection=vtk.vtkProp3DCollection()  
assembly.GetActors(collection)  
collection.InitTraversal()  
for i in range(collection.GetNumberOfItems()):  
actor=collection.GetNextProp3D()  
centers[i-1,:]=actor.GetCenter()  
return centers

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [January 19, 2023, 2:51pm UTC](https://discourse.vtk.org/t/vtk-9-2-5-python-wrapper-vtkprop3dcollection-getnextprop3d-return-null/10504/3 "2023-01-19T14:51:21Z")

</div>

Even the VTK developers themselves have trouble with the “Collection” classes.

From Python, the easiest way to use them is like this:

```
 for i in range(collection.GetNumberOfItems()):
    actor = collection.GetItemAsObject(i)

```

---

<div class="post-metadata">

### Author: ![TartaPise](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/47e85d/32.png) [@TartaPise](https://discourse.vtk.org/u/TartaPise)
#### Post date: [January 19, 2023, 2:57pm UTC](https://discourse.vtk.org/t/vtk-9-2-5-python-wrapper-vtkprop3dcollection-getnextprop3d-return-null/10504/4 "2023-01-19T14:57:40Z")

</div>

Thank you mate. My next issue is that changing the pose of the vtkassembly using RotateX() ecc does not change the center of each single actor, any idea why?

edit: I just found another post with the same issue with no answer here [https://vtk.org/pipermail/vtkusers/2018-March/101327.html](https://vtk.org/pipermail/vtkusers/2018-March/101327.html)

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [January 19, 2023, 3:02pm UTC](https://discourse.vtk.org/t/vtk-9-2-5-python-wrapper-vtkprop3dcollection-getnextprop3d-return-null/10504/5 "2023-01-19T15:02:13Z")

</div>

> My next issue is that changing the pose of the vtkassembly using RotateX() ecc does not change the center of each single actor

@will.schroeder might know the answer to that one.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [January 19, 2023, 4:52pm UTC](https://discourse.vtk.org/t/vtk-9-2-5-python-wrapper-vtkprop3dcollection-getnextprop3d-return-null/10504/6 "2023-01-19T16:52:57Z")

</div>

> [@dgobbi](#):
>
> Even the VTK developers themselves have trouble with the “Collection” classes.

Yes, the stateful iteration is annoying (basically, a call to `InitTraversal()` is required before `GetNext*` is “useful”). Also note that any collection can contain any object because of the `vtkCollection::AddItem(vtkObject*)` method.
