creating multiblock data from a datafile with a programmable source

My starting point is this example for reading a simple hex mesh:

I would like to do something similar for a multiblock mesh, for example this same hex mesh but one of the edges is an additional block. I don’t know how to change this code to tell paraview that output should be 2 blocks. Does somebody have an example on how to read and create a simple multiblock mesh ?

I found a multiblock example that can be used to create a programmable source for a multiblock here (this website was not popping up in my google searcher earlier):

To get it to work in a programmable source I just copied the first part:

    from paraview import vtk
    import os
    from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet
    from vtkmodules.vtkFiltersSources import vtkSphereSource

    # PART 1 Make some Data.
    # Make a tree.
    root = vtkMultiBlockDataSet()

    branch = vtkMultiBlockDataSet()
    root.SetBlock(0, branch)

    # Make some leaves.
    leaf1 = vtkSphereSource()
    leaf1.SetCenter(0, 0, 0)
    branch.SetBlock(0, leaf1.GetOutput())

    leaf2 = vtkSphereSource()
    leaf2.SetCenter(1.75, 2.5, 0)
    branch.SetBlock(1, leaf2.GetOutput())

    leaf3 = vtkSphereSource()
    leaf3.SetCenter(4, 0, 0)
    root.SetBlock(1, leaf3.GetOutput())


A follow-up question is: how can I set the names of the branches and leaves (that appears in the data hierarchy) ?

It is possible to specify a name for the Meta Data of each branch or leaf as shown below.

branch.GetMetaData(0).Set(vtk.vtkCompositeDataSet.NAME(), 'sphere1')
branch.GetMetaData(1).Set(vtk.vtkCompositeDataSet.NAME(), 'sphere2')
root.GetMetaData(1).Set(vtk.vtkCompositeDataSet.NAME(), 'sphere3')
1 Like