# VTKPythonAlgorithmBase for custom annotations

**URL:** https://discourse.paraview.org/t/vtkpythonalgorithmbase-for-custom-annotations/1939
**Category:** ParaView Support
**Tags:** python
**Created:** [May 28, 2019, 1:30pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-for-custom-annotations/1939 "2019-05-28T13:30:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![siver](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@siver](https://discourse.paraview.org/u/siver)
#### Post date: [May 28, 2019, 1:30pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-for-custom-annotations/1939/1 "2019-05-28T13:30:37Z")

</div>

Dear devs,

Can one use the VTKPythonAlgorithmBase class to create annotation filters, i.e. show additional descriptive text? I have managed to open a table in a separate window, but never to show a text in the same window.

I have a feeling there should be a connection to the PrintSelf function and the ostream to achieve this, is it so? Any help is deeply appreciated.

Best,  
Art

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 3, 2019, 12:53pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-for-custom-annotations/1939/2 "2019-06-03T12:53:16Z")

</div>

You may want to precise what you are trying to achieve.

---

<div class="post-metadata">

### Author: ![siver](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@siver](https://discourse.paraview.org/u/siver)
#### Post date: [June 3, 2019, 1:08pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-for-custom-annotations/1939/3 "2019-06-03T13:08:56Z")

</div>

As an execrcise, I am trying to write a PV plugin in python, that would create an annotation filter, i.e. show a text at the top of the render view window. The problem is that instead of a string I get a table in the Spread Sheet view. I also compared the python implementation with existing c++ filters, and the only thing that was different is that c++ filters have the PrintSelf function, while python filters do not.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [June 3, 2019, 1:32pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-for-custom-annotations/1939/4 "2019-06-03T13:32:05Z")

</div>

A filter indicate it’s producing data that should rendered as text by adding a hint. If your filter is producing a table with a single row/column with the string to be rendered as text in the render view, the following hint should do the trick.

```python
@smhint.xml("<OutputPort index='0' name='Output-0' type='text' />")
class Foo(VTKPythonAlgorithmBase):
   ...

```

---

<div class="post-metadata">

### Author: ![siver](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@siver](https://discourse.paraview.org/u/siver)
#### Post date: [June 11, 2019, 2:30pm UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-for-custom-annotations/1939/5 "2019-06-11T14:30:31Z")

</div>

Dear Mathieu, dear Utkarsh,

I’m sorry, but I still cannot get it right. I have added the hint as you suggested, yet I still get no text in the render view, but a table in a separate window. Here is my code:

```auto
@smproxy.filter(name="CustomAnnotationFilter", 
                label="CustomAnnotationFilter")
@smproperty.input(name="InputDataSet", port_index=0)
@smdomain.datatype(dataTypes=["vtkDataObject"], 
                   composite_data_supported=False)
@smhint.xml("<OutputPort index='0' name='output-0' type='text' />")
class ExampleTwoInputFilter(VTKPythonAlgorithmBase):
	def __init__ (self):
		VTKPythonAlgorithmBase. __init__ (self, nInputPorts=1, 
                     nOutputPorts=1, outputType="vtkTable")

	def FillInputPortInformation(self, port, info):
		info.Set(self.INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject")
		return 1

	def RequestData(self, request, inInfoVec, outInfoVec):
		output = vtkTable.GetData(outInfoVec, 0)

		data = vtk.vtkStringArray()
		data.SetName("text")
		data.SetNumberOfComponents(1)
		data.InsertNextValue("this is inserted text")

		output.AddColumn(data)
		return 1

```

Upon loading the plugin, I create a sphere from source and apply this filter.

Once again, any help is deeply appreciated, thank you.  
Art

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 14, 2019, 11:39am UTC](https://discourse.paraview.org/t/vtkpythonalgorithmbase-for-custom-annotations/1939/6 "2019-06-14T11:39:36Z")

</div>

Here is a Python text source that work out of the box.

```auto
    @smproxy.source(name="PythonText",
           label="PythonText")
    @smhint.xml("<OutputPort index='0' name='Output-0' type='text' />")
    class PythonText(VTKPythonAlgorithmBase):
        """This is dummy VTKPythonAlgorithmBase subclass that
        simply puts out a Text"""
        def __init__ (self):
            VTKPythonAlgorithmBase. __init__ (self,
                    nInputPorts=0,
                    nOutputPorts=1,
                    outputType='vtkTable')
            from paraview.modules.vtkPVVTKExtensionsDefault import vtkPVTextSource
            self._realAlgorithm = vtkPVTextSource()

        def RequestData(self, request, inInfo, outInfo):
            from vtkmodules.vtkCommonDataModel import vtkTable
            self._realAlgorithm.Update()
            output = vtkTable.GetData(outInfo, 0)
            output.ShallowCopy(self._realAlgorithm.GetOutput())
            return 1

        @smproperty.stringvector(name="Text")
        def SetText(self, text):
            self._realAlgorithm.SetText(text)
            self.Modified()

```
