# Is it possible to use the vtkDataAssemblyVisitor pattern from Python?

**URL:** https://discourse.vtk.org/t/is-it-possible-to-use-the-vtkdataassemblyvisitor-pattern-from-python/14352
**Category:** Support
**Created:** [August 3, 2024, 6:53pm UTC](https://discourse.vtk.org/t/is-it-possible-to-use-the-vtkdataassemblyvisitor-pattern-from-python/14352 "2024-08-03T18:53:55Z")
**Posts on this page:** 5
**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: [August 3, 2024, 6:53pm UTC](https://discourse.vtk.org/t/is-it-possible-to-use-the-vtkdataassemblyvisitor-pattern-from-python/14352/1 "2024-08-03T18:53:56Z")

</div>

Hello!!!

I’m working on vtkPartitionedDataSetCollections in Python and I’m trying to use the vtkDataAssemblyVisitor to traverse the associated assembly.

However, when I try to create my specialized Python class (shown below) derived from vtkDataAssemblyVisitor I get a “TypeError: this is an abstract class and cannot be instantiated” error…

Is there any way I can use this Visitor pattern from Python?

Any guidance will be gratefully received…

```auto
class VTKDatasetToApexMesh(vtkDataAssemblyVisitor):
    def __init__ (self):
        self.target=None

    def Visit(self, node):
        print('Visiting {}'.format(node))

```

---

<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: [August 7, 2024, 11:51am UTC](https://discourse.vtk.org/t/is-it-possible-to-use-the-vtkdataassemblyvisitor-pattern-from-python/14352/2 "2024-08-07T11:51:27Z")

</div>

There’s nothing in VTK’s wrapping that makes inheriting from a C++ class callable from C++ automatically. It would need something like `vtkPythonAlgorithm` that looks at the “self” object and calls Python methods in the C++ implementation to work properly.

Cc: @dgobbi, @berk.geveci, @jaswantp

---

<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: [August 7, 2024, 1:13pm UTC](https://discourse.vtk.org/t/is-it-possible-to-use-the-vtkdataassemblyvisitor-pattern-from-python/14352/3 "2024-08-07T13:13:12Z")

</div>

The VTK python wrappers don’t implement a virtual method hook that would allow this to work. By “hook”, I mean wrapper code that would call the Python subclass method (e.g. “Visit”) when the corresponding C++ virtual method is called. I know that this description makes it sound like a trivial thing, but implementing it is definitely non-trivial.

I’ve though about implementing this many times, but have never gotten around to actually doing it.

---

<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: [August 9, 2024, 10:49pm UTC](https://discourse.vtk.org/t/is-it-possible-to-use-the-vtkdataassemblyvisitor-pattern-from-python/14352/4 "2024-08-09T22:49:28Z")

</div>

Thanks David,

At least I now know for sure it isn’t going to work…

I guess I need to go back to using the tree iterator instead which isn’t quite as clean, but still workable

---

<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: [August 9, 2024, 10:50pm UTC](https://discourse.vtk.org/t/is-it-possible-to-use-the-vtkdataassemblyvisitor-pattern-from-python/14352/5 "2024-08-09T22:50:45Z")

</div>

Makes sense. I REALLY like vtkPythonAlgorithm… 🙂
