# How to get block indexes in Python

**URL:** https://discourse.paraview.org/t/how-to-get-block-indexes-in-python/797
**Category:** ParaView Support
**Created:** [October 25, 2018, 6:40pm UTC](https://discourse.paraview.org/t/how-to-get-block-indexes-in-python/797 "2018-10-25T18:40:04Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/banesullivan/32/11714_2.png) [@banesullivan](https://discourse.paraview.org/u/banesullivan)
#### Post date: [October 26, 2018, 4:55am UTC](https://discourse.paraview.org/t/how-to-get-block-indexes-in-python/797/2 "2018-10-26T04:55:33Z")

</div>

Just to be clear, you have a composite dataset containing `vtkImageData` objects which each have a unique name and you would like to save those out to their own files? I believe ParaView’s native image data writer can handle this… If you are using some custom format there are a few ways you could grab the name:

## Grab the name while scripting

To get the name of any block in an input composite dataset:

```auto
from paraview.simple import *
from paraview.servermanager import Fetch
import vtk

# Find the server manager source on the pipeline
src = FindSource('inputData')
# Get the VTK data object from that source
obj = Fetch(src)

# Grab the name for any index
index = 0
name = obj.GetMetaData(index).Get(vtk.vtkCompositeDataSet.NAME())

```

## Make a custom writer plugin

Using ParaView 5.6’s new [Python Algorithm plugin capability](https://gitlab.kitware.com/paraview/paraview/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py), you could create a custom writer plugin much like an example I demonstrate in [this snippet](https://gitlab.kitware.com/paraview/paraview/snippets/425) which I have updated to pass the composite dataset’s names [here](https://github.com/OpenGeoVis/PVGeo/blob/master/snippets/PV_Composite_Writer.py). Note that these base classes are fully implemented in [**PVGeo**](http://pvgeo.org).

For your case, you could create a plugin inheriting from the demonstrated `WriterBase` class in the following manner (this is only [a part of the shared snippet from the PVGeo repository](https://github.com/OpenGeoVis/PVGeo/blob/master/snippets/PV_Composite_Writer.py#L221)):

```auto
@smproxy.writer(extensions="imgfmt", file_description="Write Custom ImageData", support_reload=False)
@smproperty.input(name="Input", port_index=0)
@smdomain.datatype(dataTypes=["vtkImageData"], composite_data_supported=True)
class WriteCustomImageData(WriterBase):
    """This is an example of how to make your own file writer!

    .. _PVGeo: http://pvgeo.org
    .. _Bane Sullivan: http://banesullivan.com
    """
    def __init__ (self):
        WriterBase. __init__ (self, inputType='vtkImageData')
        self.__delimiter = ','

    def PerformWriteOut(self, inputDataObject, filename, objectName):
        """Perfrom the file write to the given FileName with the given data
        object. The super class handles all the complicated stuff.
        """
        fname = filename.split('.')
        fname = '.'.join(fname[0:-1]) + '_%s.%s' % (objectName, fname[-1])
        writer = vtk.vtkXMLImageDataWriter()
        writer.SetFileName(fname)
        writer.SetInputDataObject(inputDataObject)
        writer.Write()
        # Success for pipeline
        return 1

    @smproperty.stringvector(name="FileName", panel_visibility="never")
    @smdomain.filelist()
    def SetFileName(self, fname):
        """Specify filename for the file to write."""
        WriterBase.SetFileName(self, fname)

```

---

_[View the full topic](https://discourse.paraview.org/t/how-to-get-block-indexes-in-python/797)._
