# Can flat indices from CompositeDataSetIterators be used to recover nodes from vtkDataAssembly?

**URL:** https://discourse.vtk.org/t/can-flat-indices-from-compositedatasetiterators-be-used-to-recover-nodes-from-vtkdataassembly/15410
**Category:** Support
**Tags:** vtkpartitioneddatase, vtkdatassembly, python
**Created:** [March 20, 2025, 11:03pm UTC](https://discourse.vtk.org/t/can-flat-indices-from-compositedatasetiterators-be-used-to-recover-nodes-from-vtkdataassembly/15410 "2025-03-20T23:03:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [March 20, 2025, 11:03pm UTC](https://discourse.vtk.org/t/can-flat-indices-from-compositedatasetiterators-be-used-to-recover-nodes-from-vtkdataassembly/15410/1 "2025-03-20T23:03:54Z")

</div>

Hello!!!

I’m uinsg VTK 9.2, Python 3.11.6 and I’ll be grateful for any help with this…

I have a vtkPartitionedDataSetCollection and associated vtkDataAssembly representing a hierarchial Part/Assembly structure. I have carefully added attributes to the vtkDataAssembly nodes that are important to my application.

When I iterate over the vtkPartitionedDataSetCollection, I call iter.GetCurrentFlatIndex() and pass the value into my assembly, expecting to get the nodePath, nodeName etc of the assembly node that the dataset is associated with - which I can then use to retrieve the attributes from the node

But I’m finding that I’m getting the wrong/unexpected assembly node back - it doesn’t match the node that the dataset is associated with.

So my questions are,

1. Is this the recommended approach to link datasets with assembly nodes?
2. If not, what _is_ the recommended approach?
3. If so, why is not working…

Here is a minimal code example and I’ve attached a test file

```auto
# coding: utf-8
    
from vtkmodules.vtkIOXML import vtkXMLPartitionedDataSetCollectionReader    

# Read the vtkPatitionedDataSetCollection
reader=vtkXMLPartitionedDataSetCollectionReader()
reader.SetFileName('E:/DEV/test_to_vtk.vtpc')
reader.Update()
pdsc=reader.GetOutputDataObject(0)

# Get hte vtkDataAssembly
assy=pdsc.GetDataAssembly()

# Iterate over the collection
iter=pdsc.NewIterator()
#iter.VisitOnlyLeavesOff()
#iter.SkipEmptyNodesOff()
iter.InitTraversal()
iter.GoToFirstItem()

mesh_bodies_referencing_node=[]
while iter.IsDoneWithTraversal()==0:
    dset=iter.GetCurrentDataObject()

    # Get the flat index and use it to recover the assembly node info
    nodepath=assy.GetNodePath(iter.GetCurrentFlatIndex())
    nodename=assy.GetNodeName(iter.GetCurrentFlatIndex())
    print(iter.GetCurrentFlatIndex(), nodepath, nodename, type(dset), dset.GetNumberOfPoints())
    if assy.HasAttribute(iter.GetCurrentFlatIndex(), 'entityType'):
        print(assy.GetAttributeOrDefault(iter.GetCurrentFlatIndex(), 'entityType', 'Unknown'))
    else:
        print('No entityType attribute found for node with id {}'.format(iter.GetCurrentFlatIndex()))
    iter.GoToNextItem()  

exit()

```

[test\_to\_vtk.vtpc](https://discourse.vtk.org/uploads/short-url/p7D2rDTGAp3xBukAIls9p6DzuAX.vtpc) (4.1 KB)  
[test\_to\_vtk.zip](https://discourse.vtk.org/uploads/short-url/f9FCeK2w4Sa24MYvBTZedrDjZLb.zip) (11.6 KB)

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [March 21, 2025, 8:23pm UTC](https://discourse.vtk.org/t/can-flat-indices-from-compositedatasetiterators-be-used-to-recover-nodes-from-vtkdataassembly/15410/2 "2025-03-21T20:23:53Z")

</div>

Added the actual files that the .vtpc references…
