# Filter to apply variable to blockID

**URL:** https://discourse.paraview.org/t/filter-to-apply-variable-to-blockid/7384
**Category:** ParaView Support
**Created:** [June 8, 2021, 8:46pm UTC](https://discourse.paraview.org/t/filter-to-apply-variable-to-blockid/7384 "2021-06-08T20:46:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Lukasz\_Kuna](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lukasz_kuna/32/6851_2.png) [@Lukasz\_Kuna](https://discourse.paraview.org/u/Lukasz_Kuna)
#### Post date: [June 8, 2021, 8:46pm UTC](https://discourse.paraview.org/t/filter-to-apply-variable-to-blockid/7384/1 "2021-06-08T20:46:58Z")

</div>

Hi All,  
I’ve been trying to transform some data I have output from a C++ code I have developed. It is an exodus file with elemental variables. My simulations involve grains from solidification and output a voxel mesh. I am able to load this Paraview and see my gID elemental variable, but I need a way to have those variables be assigned as the BlockID (for further processing and mesh clean up in Cubit). Is there a way to do this in Paraview?

Thanks!  
P.S. I can provide a sample exodus to demonstrate my issue upon request.

---

<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: [June 10, 2021, 12:03am UTC](https://discourse.paraview.org/t/filter-to-apply-variable-to-blockid/7384/2 "2021-06-10T00:03:12Z")

</div>

Hello,

One way might be to use the **vtkSplitByCellScalarFilter** included in the vtk library in the Programmable Filter.

The procedure is to load the exodus file into ParaView, then use the **Merge Blocks filter** to convert it to _Unstructured Grid_, and then apply the **Programmable filter**. In the Programmable filter, set the **Output Data Set Type** to _vtkMultiBlockDataSet_, and write the following code in the **Script** field.

```python
import vtk

input = self.GetInput()
output = self.GetOutput()

splitter = vtk.vtkSplitByCellScalarFilter()
splitter.SetInputData(input)
splitter.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS, "gID")
splitter.PassAllPointsOff()
splitter.Update()

output.ShallowCopy(splitter.GetOutput())

```

---

<div class="post-metadata">

### Author: ![Lukasz\_Kuna](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lukasz_kuna/32/6851_2.png) [@Lukasz\_Kuna](https://discourse.paraview.org/u/Lukasz_Kuna)
#### Post date: [June 10, 2021, 8:11pm UTC](https://discourse.paraview.org/t/filter-to-apply-variable-to-blockid/7384/3 "2021-06-10T20:11:18Z")

</div>

Hi Kyoshimi,  
I tried your approach and unfortunately while the script does successfully create vtkBlockColors, I have no way to export this as BlockIDs. The exodus I export still only has one BlockID. Additionally I get an error “Block ids are not unique across the hierarchy”. It seems that although I can make vtkBlockColors, there is no way to export. I have attached a sample mesh if anyone would like to recreate the issue, or give this a try.

Thanks  
[Exodus\_Example.tar.gz](https://discourse.paraview.org/uploads/short-url/uW5LDamZRPN2kG6X0KXCwfYZlPe.gz) (168.1 KB)

---

<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: [June 11, 2021, 4:26am UTC](https://discourse.paraview.org/t/filter-to-apply-variable-to-blockid/7384/4 "2021-06-11T04:26:04Z")

</div>

Hello,

After saving the file as VTK Multi Block Files (\*.vtm), how about adding a “Block” tag around each “DataSet” tag in the vtm file, as shown below?

```xml
<VTKFile type="vtkMultiBlockDataSet" version="1.0" byte_order="LittleEndian" header_type="UInt64">
  <vtkMultiBlockDataSet>
    <DataSet index="0" name="int_gID_72" file="aaa/aaa_0_0.vtu"/>
    <DataSet index="1" name="int_gID_323" file="aaa/aaa_1_0.vtu"/>
    <DataSet index="2" name="int_gID_239" file="aaa/aaa_2_0.vtu"/>

```

----\>

```xml
<VTKFile type="vtkMultiBlockDataSet" version="1.0" byte_order="LittleEndian" header_type="UInt64">
  <vtkMultiBlockDataSet>
    <Block index="0" name="Blocks_0">
      <DataSet index="0" name="int_gID_72" file="aaa/aaa_0_0.vtu"/>
    </Block>
    <Block index="1" name="Blocks_1">
      <DataSet index="0" name="int_gID_323" file="aaa/aaa_1_0.vtu"/>
    </Block>
    <Block index="2" name="Blocks_2">
      <DataSet index="0" name="int_gID_239" file="aaa/aaa_2_0.vtu"/>
    </Block>

```

P.S. For doing this, you could use, for example, a simple Python script like the one attached:  
[create\_blockId.py](https://discourse.paraview.org/uploads/short-url/j94WOEXIlBqoAWFkjK1stWQpKwB.py) (773 Bytes)

`python create_blockId.py -i aaa.vtm -o out.vtm`
