How to get block indexes in Python

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:

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, you could create a custom writer plugin much like an example I demonstrate in this snippet which I have updated to pass the composite dataset’s names here. Note that these base classes are fully implemented in PVGeo.

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):

@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)