Extracting patches by name from EnsightGold file - pvpython

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

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

_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

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

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

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)