# Extract Block python code

**URL:** https://discourse.paraview.org/t/extract-block-python-code/12808
**Category:** ParaView Support
**Tags:** python
**Created:** [September 4, 2023, 10:27am UTC](https://discourse.paraview.org/t/extract-block-python-code/12808 "2023-09-04T10:27:47Z")
**Posts on this page:** 5
**Page:** 1

<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 4, 2023, 10:27am UTC](https://discourse.paraview.org/t/extract-block-python-code/12808/1 "2023-09-04T10:27:47Z")

</div>

I have a problem trying to write the python code for the extract block selector part.  
In my company we simulate with a CFD that give us a case.foam nomenclature that we can not predict. We know the baseline of B…\_TES…\_B…\_TES…, but we can not predict the numbers on it (see the image).  
In my code i want to do an extract block of only the parts we can not predict, in resume, i want to select with my code the whole boundary block, removing the Boundary box (see the image.)

 ![Captura de pantalla 2023-09-04 122056](https://discourse.paraview.org/uploads/default/original/2X/0/05afd8b9bbf4c1ecdb80b6b0dfb8013c51d5ef2e.jpeg)  
When i write the code, the way of selecting the properties of the extract block is:

![image](https://discourse.paraview.org/uploads/default/original/2X/d/d5806976453c2d17e65a53b045c158293f848c58.png)

If i unselect the boundary boxes, the code is:

 ![image](https://discourse.paraview.org/uploads/default/original/2X/4/4cd77a0dc68d5095a2049a1bf94c30b4763b448e.png)

So my code doesnt work for my iterations, because in each one, the nomenclature, is different.  
There is any way of selecting the block ‘boundary’, and then unselecting the boundary box?  
How you will solve my problem?  
Thank for your help.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 4, 2023, 1:52pm UTC](https://discourse.paraview.org/t/extract-block-python-code/12808/2 "2023-09-04T13:52:33Z")

</div>

Which version of ParaView are you using ?

---

<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 4, 2023, 2:06pm UTC](https://discourse.paraview.org/t/extract-block-python-code/12808/3 "2023-09-04T14:06:57Z")

</div>

5.11.0

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 4, 2023, 2:12pm UTC](https://discourse.paraview.org/t/extract-block-python-code/12808/4 "2023-09-04T14:12:39Z")

</div>

You technically cannot unselect a block however you can just not select anything like this:

```auto
extractBlock2.Selectors = []

```

---

<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, 10:44am UTC](https://discourse.paraview.org/t/extract-block-python-code/12808/5 "2023-09-27T10:44:54Z")

</div>

The best I could do for now is:

First select the boundaries, and

```auto
extractBlock1.Selectors = ['/Root/boundary']
extractBlock1Display = GetDisplayProperties(extractBlock1, view=renderView1)
renderView1.Update()

```

Then I managed to get the loaded block names like this:

```auto
blocks = []
i=0
while True:
  name = extractBlock1.GetDataInformation().DataInformation.GetBlockName(i)
  if name =='': break
  blocks.append(name)
  i+=1

```

Then you can do some python list operations to remove vtkMultiBlockDataSet and boundary, and any boundaries you don’t want to select.

Then add the boundary prefix back in and set your Selector using the list

```auto
blocks = ['/Root/boundary/' + block for block in blocks]
extractBlock1.Selectors = blocks

```
