# Extracting patches by name from EnsightGold file - pvpython

**URL:** https://discourse.paraview.org/t/extracting-patches-by-name-from-ensightgold-file-pvpython/6599
**Category:** ParaView Support
**Tags:** python
**Created:** [March 3, 2021, 3:27pm UTC](https://discourse.paraview.org/t/extracting-patches-by-name-from-ensightgold-file-pvpython/6599 "2021-03-03T15:27:13Z")
**Posts on this page:** 5
**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: [March 3, 2021, 3:27pm UTC](https://discourse.paraview.org/t/extracting-patches-by-name-from-ensightgold-file-pvpython/6599/1 "2021-03-03T15:27:13Z")

</div>

Dear all,  
I am dealing with an EnsightGold file representing a CFD solution on a mesh with several boundary patches. I need to extract the ‘inlet’ and ‘outlet’ patches to perform the post-processing. I need to apply an extractBlock filter on the solution and get these patches. I would like to make the python script general so I would need to choose by name the block to extract or at least to know the index number corresponding to any block. I found some possible solutions on the net but none of them worked for my case.  
The functions that I tried are reported below:

> ```
> def GetBlockIndices(source, name):
> indices = []
> it = servermanager.vtkPVCompositeDataInformationIterator()
> it.SetDataInformation(source.GetDataInformation().DataInformation)
> it.InitTraversal()
> while not it.IsDoneWithTraversal():
> if it.GetCurrentName() == name:
> indices.append(it.GetCurrentFlatIndex())
> it.GoToNextItem()
> del it
> return indices
> 
> ```

> 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

Looks like the number of children is zero and GetName method always returns None. The thing is that opening the GUI and using it to extract the patches everything works.

Anyone has an idea about how to make the script work?

Thanks in advance,  
Lorenzo

---

<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: [March 3, 2021, 3:52pm UTC](https://discourse.paraview.org/t/extracting-patches-by-name-from-ensightgold-file-pvpython/6599/2 "2021-03-03T15:52:46Z")

</div>

Your last function looks awfully similar to whata I am using.  
it needs the compositeDataInformation as input and not the extractblock filter itself:

```auto
_lookUpTable, _ = getBlockIndices(extractBlockFilter.GetDataInformation().GetCompositeDataInformation())

```

are you using it this way ?

the loop up table should then contains the block names as keys, and the block indices as values

---

<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: [March 3, 2021, 7:29pm UTC](https://discourse.paraview.org/t/extracting-patches-by-name-from-ensightgold-file-pvpython/6599/3 "2021-03-03T19:29:49Z")

</div>

Yes, I’m not using the extractBlock filter as source but directly the EnsightReader (Ensightcase.GetDataInformation().DataInformation.GetCompositeDataInformation()))

---

<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: [March 4, 2021, 7:47am UTC](https://discourse.paraview.org/t/extracting-patches-by-name-from-ensightgold-file-pvpython/6599/4 "2021-03-04T07:47:45Z")

</div>

That makes sense. Do you see the multiblock structure in the properties panels of the ensightreader source ? what does it look like ?

---

<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: [March 4, 2021, 10:32am UTC](https://discourse.paraview.org/t/extracting-patches-by-name-from-ensightgold-file-pvpython/6599/5 "2021-03-04T10:32:23Z")

</div>

Thanks for making me think better about it.  
The problem was that when I applied the functions the reader was not yet updated, just needed the following command to make everything work:

> UpdatePipeline(time=0.0, proxy=Ensightcase)
