# creating multiblock data from a datafile with a programmable source

**URL:** https://discourse.paraview.org/t/creating-multiblock-data-from-a-datafile-with-a-programmable-source/9495
**Category:** ParaView Support
**Created:** [April 21, 2022, 9:53pm UTC](https://discourse.paraview.org/t/creating-multiblock-data-from-a-datafile-with-a-programmable-source/9495 "2022-04-21T21:53:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bigfooted](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bigfooted/32/6347_2.png) [@bigfooted](https://discourse.paraview.org/u/bigfooted)
#### Post date: [April 21, 2022, 9:53pm UTC](https://discourse.paraview.org/t/creating-multiblock-data-from-a-datafile-with-a-programmable-source/9495/1 "2022-04-21T21:53:08Z")

</div>

My starting point is this example for reading a simple hex mesh:  
[https://www.paraview.org/Wiki/ParaView/Simple\_ParaView\_3\_Python\_Filters#Producing\_An\_Unstructured\_Grid\_(Source)](https://www.paraview.org/Wiki/ParaView/Simple_ParaView_3_Python_Filters#Producing_An_Unstructured_Grid_(Source))

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 ?

---

<div class="post-metadata">

### Author: ![bigfooted](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bigfooted/32/6347_2.png) [@bigfooted](https://discourse.paraview.org/u/bigfooted)
#### Post date: [April 25, 2022, 8:20pm UTC](https://discourse.paraview.org/t/creating-multiblock-data-from-a-datafile-with-a-programmable-source/9495/2 "2022-04-25T20:20:18Z")

</div>

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):  
[https://kitware.github.io/vtk-examples/site/Python/CompositeData/MultiBlockDataSet/](https://kitware.github.io/vtk-examples/site/Python/CompositeData/MultiBlockDataSet/)

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

```auto
    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)
    leaf1.Update()
    branch.SetBlock(0, leaf1.GetOutput())

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

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

    output.DeepCopy(root)      

```

---

<div class="post-metadata">

### Author: ![bigfooted](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bigfooted/32/6347_2.png) [@bigfooted](https://discourse.paraview.org/u/bigfooted)
#### Post date: [April 25, 2022, 9:57pm UTC](https://discourse.paraview.org/t/creating-multiblock-data-from-a-datafile-with-a-programmable-source/9495/3 "2022-04-25T21:57:48Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [April 25, 2022, 11:39pm UTC](https://discourse.paraview.org/t/creating-multiblock-data-from-a-datafile-with-a-programmable-source/9495/4 "2022-04-25T23:39:30Z")

</div>

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

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

```
