# vtkDataObject subclassing example \[python\]

**URL:** https://discourse.vtk.org/t/vtkdataobject-subclassing-example-python/7619
**Category:** Support
**Created:** [January 12, 2022, 12:57am UTC](https://discourse.vtk.org/t/vtkdataobject-subclassing-example-python/7619 "2022-01-12T00:57:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nicholas\_Yue](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicholas_yue/32/3751_2.png) [@Nicholas\_Yue](https://discourse.vtk.org/u/Nicholas_Yue)
#### Post date: [January 12, 2022, 12:57am UTC](https://discourse.vtk.org/t/vtkdataobject-subclassing-example-python/7619/1 "2022-01-12T00:57:32Z")

</div>

I would like to pass customised data types into and out of a vtkAlgorithm subclass

Where can I find more python information about subclass vtkDataObject

The following is the gist of my idea of what I am trying to acheive

```auto
class MyCommandData(vtk.vtkDataObject):
    def __init__ (self):
        super(MyCommandData, self). __init__ (self)
        self.stdin = ''
        self.stdout = ''
        self.stderr = ''
        self.retcode = 0

class MyCommand(vtk.vtkAlgorithm):

    def __init__ (self):
        super(MyCommand, self). __init__ (self,
                                        nInputPorts=1, inputType='MyCommandData',
                                        nOutputPorts=1, outputType='MyCommandData')

    def FillInputPortInformation(self, port, info):
        if port == 0:
            info.Set(vtk.vtkAlgorithm.INPUT_IS_OPTIONAL(), 1)
        return 1

```

---

<div class="post-metadata">

### Author: ![Nicholas\_Yue](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicholas_yue/32/3751_2.png) [@Nicholas\_Yue](https://discourse.vtk.org/u/Nicholas_Yue)
#### Post date: [January 12, 2022, 1:38am UTC](https://discourse.vtk.org/t/vtkdataobject-subclassing-example-python/7619/2 "2022-01-12T01:38:13Z")

</div>

I have make some progress with the following but it thinks my custom data is not define

```auto
import vtk
from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase

class MyCommandData(vtk.vtkDataObject):
    def __init__ (self):
        super(MyCommandData, self). __init__ ()
        self.stdin = ''
        self.stdout = ''
        self.stderr = ''
        self.retcode = 0

class MyCommand(VTKPythonAlgorithmBase):

    def __init__ (self):
        super(MyCommand, self). __init__ (nInputPorts=1, inputType='MyCommandData',
                                        nOutputPorts=1, outputType='MyCommandData')

    def FillInputPortInformation(self, port, info):
        if port == 0:
            info.Set(vtk.vtkAlgorithm.INPUT_IS_OPTIONAL(), 1)
            info.Set(vtk.vtkDataObject.DATA_TYPE_NAME(),'MyCommandData')
        return 1

    def FillOutputPortInformation(self, port, info):
        if port == 0:
            info.Set(vtk.vtkDataObject.DATA_TYPE_NAME(),'MyCommandData')
        return 1

    def RequestData(self, request, inInfo, outInfo):
        input_info = inInfo[0].GetInformationObject(0)
        input = MyCommandData.GetData(input_info)
        output_info = outInfo.GetInformationObject(0)
        output = MyCommandData.GetData(output_info)
        return 1

a = MyCommand()
b = MyCommand()
b.AddInputConnection(0, a.GetOutputPort())
b.Update()

```

Output is

```auto
2022-01-11 17:34:58.297 ( 0.149s) [4EC3080] vtkDataObjectTypes.cxx:296 WARN| NewDataObject(): You are trying to instantiate DataObjectType "MyCommandData" which does not exist.
2022-01-11 17:34:58.297 ( 0.149s) [4EC3080]vtkDemandDrivenPipeline:615 ERR| vtkCompositeDataPipeline (0x5590416af7b0): Algorithm vtkPythonAlgorithm(0x5590416ae360) did not create output for port 0 when asked by REQUEST_DATA_OBJECT and does not specify a concrete DATA_TYPE_NAME.

```

---

<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 21, 2022, 1:24pm UTC](https://discourse.vtk.org/t/vtkdataobject-subclassing-example-python/7619/3 "2022-01-21T13:24:14Z")

</div>

It is not possible to subclass VTK objects from Python in ways that the C++ code is aware of them as there is no “glue” class which C+±inherits from arbitrary VTK classes and forwards requests to Python code (as is done for `VTKPythonAlgorithmBase`).
