# Get block name and ID from multiblock dataset

**URL:** https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014
**Category:** ParaView Support
**Tags:** python
**Created:** [April 9, 2020, 8:44am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014 "2020-04-09T08:44:49Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Lorenzo\_Cozzi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lorenzo_cozzi/32/3171_2.png) [@Lorenzo\_Cozzi](https://discourse.paraview.org/u/Lorenzo_Cozzi)
#### Post date: [April 9, 2020, 8:44am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/1 "2020-04-09T08:44:49Z")

</div>

I’m trying to post-process an openFOAM simulation and I need to perform the analysis on one of the blocks of the solution (the one referring to the wall patch called ‘plate’). I need to apply an extractBlock filter on the solution and get this patch. The point is that I saw that the block index can vary from case to case and I would like to select the block to extract by its name (‘plate’). I there a way to do this?  
This is what my spript currently looks like:

> from paraview.simple import \*  
> import os  
> import vtk.numpy\_interface.dataset\_adapter as dsa  
> import numpy as np  
> casefoam = OpenFOAMReader(FileName=‘case.foam’)  
> casefoam.MeshRegions = [‘inlet’, ‘internalMesh’, ‘outlet’, ‘plate’, ‘side1’, ‘side2’, ‘upperWall’]  
> animationScene1 = GetAnimationScene()  
> animationScene1.GoToLast()  
> extractBlock1 = ExtractBlock(Input=casefoam)  
> extractBlock1.BlockIndices = [5]

I’d like to find a way to know what index is assigned to every mesh region name.

Thanks in advance!

---

<div class="post-metadata">

### Author: ![paulfinn](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@paulfinn](https://discourse.paraview.org/u/paulfinn)
#### Post date: [April 16, 2020, 9:37am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/2 "2020-04-16T09:37:09Z")

</div>

Hello Lorenzo,

I´m trying to extract the Blockindices of my multiblock-dataset aswell. Do you have a solution for this task by now?

Tank you in advance,  
Paul

---

<div class="post-metadata">

### Author: ![pcrepier](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/f4b2a3/32.png) [@pcrepier](https://discourse.paraview.org/u/pcrepier)
#### Post date: [April 16, 2020, 10:14am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/3 "2020-04-16T10:14:03Z")

</div>

Hi everyone,

A while ago I faced the same problem and took the time to write a small function that returns a dictionnary in which the key is the block name, and the value is the block index. It looks like this:

```python
def getBlockIndices(compositeDataInformation, index=0):

    localDict = {}

    if compositeDataInformation.GetDataIsMultiPiece():
        index += compositeDataInformation.GetNumberOfChildren()
    else:
        if compositeDataInformation.GetDataIsComposite():
            for i in range(compositeDataInformation.GetNumberOfChildren()):
                index += 1
                _blockName = compositeDataInformation.GetName(i)
                localDict[_blockName] = index
                leafDict, index = getBlockIndices(compositeDataInformation.GetDataInformation(i).GetCompositeDataInformation(), index)
                localDict.update(leafDict)

    return localDict, index

#Usage:
getBlockIndices(yourMultiBlockSourceorFilter.GetDataInformation().DataInformation.GetCompositeDataInformation())

```

Hope this helps.

---

<div class="post-metadata">

### Author: ![paulfinn](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@paulfinn](https://discourse.paraview.org/u/paulfinn)
#### Post date: [April 16, 2020, 12:17pm UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/4 "2020-04-16T12:17:43Z")

</div>

Thank you so much for your help!

I´m still struggeling to run this srcipt (sorry, I´m really new to ParaView/Python).  
What exactly do I have to insert in “yourMultiBlockSourceorFilter.” ?  
I already tried the filepath of my input file but it´s not working…  
Again, thank you for your support!

---

<div class="post-metadata">

### Author: ![pcrepier](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/f4b2a3/32.png) [@pcrepier](https://discourse.paraview.org/u/pcrepier)
#### Post date: [April 16, 2020, 12:21pm UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/5 "2020-04-16T12:21:44Z")

</div>

It should be the object in which you read your file, not the filename directly.

so in the example for the first post, that should be “casefoam”

---

<div class="post-metadata">

### Author: ![paulfinn](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@paulfinn](https://discourse.paraview.org/u/paulfinn)
#### Post date: [April 17, 2020, 8:27am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/6 "2020-04-17T08:27:54Z")

</div>

Okay. I´m still not able to extract the Indices. The file format of my input file in Paraview is .plt or .e. Could this be a part of the problem? I would like to extract the Indices form the Blocks “FuselageBugSection\_01, FuselageBugSection\_02,…” (picture). I´ve managed to get the names of the Element Blocks with “.ElementBlocks.Available” but this contains no information about the Blockindices. ![Paraview](https://discourse.paraview.org/uploads/default/original/2X/0/0f6c0d7876ceeaa3cd5ba0b4b43058d0e5d27852.png)

---

<div class="post-metadata">

### Author: ![pcrepier](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/f4b2a3/32.png) [@pcrepier](https://discourse.paraview.org/u/pcrepier)
#### Post date: [April 17, 2020, 9:02am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/7 "2020-04-17T09:02:06Z")

</div>

can you share the python code you use to process the data ?  
The function is meant to be used in a script, not from the GUI

---

<div class="post-metadata">

### Author: ![paulfinn](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@paulfinn](https://discourse.paraview.org/u/paulfinn)
#### Post date: [April 17, 2020, 9:40am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/8 "2020-04-17T09:40:39Z")

</div>

I use this code to get the names of the ElementBlocks. In this case I opened the exodusfile to get the names.

```
from paraview.simple import *

reader = ExodusIIReader(FileName=['C:\\Users\\paul\\........\\exodusfile.e'])
name=reader.ElementBlocks.Available

print(name)

```

To get the Indices with youre function, I tried this:

```
from paraview.simple import *

reader = ExodusIIReader(FileName=['C:\\Users\\paul\\.........\\exodusfile.e'])

def getBlockIndices(compositeDataInformation, index=0):

    localDict = {}

    if compositeDataInformation.GetDataIsMultiPiece():
        index += compositeDataInformation.GetNumberOfChildren()
    else:
        if compositeDataInformation.GetDataIsComposite():
            for i in range(compositeDataInformation.GetNumberOfChildren()):
                index += 1
                _blockName = compositeDataInformation.GetName(i)
                localDict[_blockName] = index
                leafDict, index = getBlockIndices(compositeDataInformation.GetDataInformation(i).GetCompositeDataInformation(), index)
                localDict.update(leafDict)

    return localDict, index

Indices=getBlockIndices(reader.GetDataInformation().DataInformation.GetCompositeDataInformation())
print(Indices)

```

But it only prints out “({}, 0)”.

Thank you again for your kind support!

---

<div class="post-metadata">

### Author: ![pcrepier](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/f4b2a3/32.png) [@pcrepier](https://discourse.paraview.org/u/pcrepier)
#### Post date: [April 17, 2020, 9:50am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/9 "2020-04-17T09:50:14Z")

</div>

That’s indeed the way to use it.  
I’ve never worked with exodus format.

Have you tried with the tecplot (.plt) file ? that should work. the print(Indices) should return some content

---

<div class="post-metadata">

### Author: ![paulfinn](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@paulfinn](https://discourse.paraview.org/u/paulfinn)
#### Post date: [April 17, 2020, 9:55am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/10 "2020-04-17T09:55:06Z")

</div>

I´ve tried to use the following code but it prints out the same results. Is “OpenDataFile” the right way to read the .plt file?

```
from paraview.simple import *

reader = OpenDataFile('C:\\Users\\paul\\.............\\techplotfile.plt')

def getBlockIndices(compositeDataInformation, index=0):

    localDict = {}

    if compositeDataInformation.GetDataIsMultiPiece():
        index += compositeDataInformation.GetNumberOfChildren()
    else:
        if compositeDataInformation.GetDataIsComposite():
            for i in range(compositeDataInformation.GetNumberOfChildren()):
                index += 1
                _blockName = compositeDataInformation.GetName(i)
                localDict[_blockName] = index
                leafDict, index = getBlockIndices(compositeDataInformation.GetDataInformation(i).GetCompositeDataInformation(), index)
                localDict.update(leafDict)

    return localDict, index

Indices=getBlockIndices(reader.GetDataInformation().DataInformation.GetCompositeDataInformation())
print(Indices)
```

---

<div class="post-metadata">

### Author: ![pcrepier](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/f4b2a3/32.png) [@pcrepier](https://discourse.paraview.org/u/pcrepier)
#### Post date: [April 17, 2020, 10:05am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/11 "2020-04-17T10:05:35Z")

</div>

can you eventually share your plt file ?

---

<div class="post-metadata">

### Author: ![Edward\_Hurst](https://discourse.paraview.org/user_avatar/discourse.paraview.org/edward_hurst/32/8538_2.png) [@Edward\_Hurst](https://discourse.paraview.org/u/Edward_Hurst)
#### Post date: [February 4, 2022, 4:46pm UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/12 "2022-02-04T16:46:12Z")

</div>

I found that this only works once all the parts are imported, otherwise it returns that there is nothing in the tree. If you select BlockIndices=[0] it imports everything, so I did something like this:  
`
extractBlock1 = ExtractBlock(registrationName=‘ExtractBlock1’, Input=‘case.foam’)
extractBlock1.BlockIndices = [0]
renderView1 = GetActiveViewOrCreate(‘RenderView’)
extractBlock1Display = Show(extractBlock1, renderView1, ‘GeometryRepresentation’)
`

Then I could use the above code to create the full dictionary, then select individual blocks by name, convert it to a list and set `extractBlock1.BlockIndices` using the new list.

---

<div class="post-metadata">

### Author: ![RafaMADFT](https://discourse.paraview.org/user_avatar/discourse.paraview.org/rafamadft/32/12344_2.png) [@RafaMADFT](https://discourse.paraview.org/u/RafaMADFT)
#### Post date: [September 26, 2023, 1:47pm UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/13 "2023-09-26T13:47:59Z")

</div>

Hi, when i run this function with ParaView-5.8.0 it works perfectly, but when i run it with the latest version, \ParaView-5.11.0, does not work.  
Do you know if i have to add any command or something similar?  
Thank you.

---

<div class="post-metadata">

### Author: ![Edward\_Hurst](https://discourse.paraview.org/user_avatar/discourse.paraview.org/edward_hurst/32/8538_2.png) [@Edward\_Hurst](https://discourse.paraview.org/u/Edward_Hurst)
#### Post date: [September 27, 2023, 9:40am UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/14 "2023-09-27T09:40:59Z")

</div>

Hi Rafael,

It seems that the method has changed for how extract blocks are defined.

You can directly select the names with the Selectors function:  
extractBlock1.Selectors = [‘/Root/boundary/inletOutlet’,‘/Root/internalMesh’]

Note: there is a bit of an issue with parts containing a ‘-’, it just gets removed so part-name would become partname

---

<div class="post-metadata">

### Author: ![codygo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/codygo/32/13942_2.png) [@codygo](https://discourse.paraview.org/u/codygo)
#### Post date: [March 14, 2024, 6:21pm UTC](https://discourse.paraview.org/t/get-block-name-and-id-from-multiblock-dataset/4014/15 "2024-03-14T18:21:26Z")

</div>

I have many multiblock datasets where “Selectors” list is unknown a priori.

I’d like to loop through a given multiblock and integrate variables per block and output a table of blockname1, integrated\_var1, integrated\_var2,…, but I don’t see documentation on where to find the list of blocks within a multiBlock object.

How does one get the list of available Selectors, using python, in the new method?
