My starting point is this example for reading a simple hex mesh:
https://www.paraview.org/Wiki/ParaView/Simple_ParaView_3_Python_Filters#Producing_An_Unstructured_Grid_(Source)
I would like to do something similar for a multiblock mesh, for example this same hex mesh but one of the edges is an additional block. I don’t know how to change this code to tell paraview that output should be 2 blocks. Does somebody have an example on how to read and create a simple multiblock mesh ?
I found a multiblock example that can be used to create a programmable source for a multiblock here (this website was not popping up in my google searcher earlier):
https://kitware.github.io/vtk-examples/site/Python/CompositeData/MultiBlockDataSet/
To get it to work in a programmable source I just copied the first part:
from paraview import vtk
import os
from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet
from vtkmodules.vtkFiltersSources import vtkSphereSource
# PART 1 Make some Data.
# Make a tree.
root = vtkMultiBlockDataSet()
branch = vtkMultiBlockDataSet()
root.SetBlock(0, branch)
# Make some leaves.
leaf1 = vtkSphereSource()
leaf1.SetCenter(0, 0, 0)
leaf1.Update()
branch.SetBlock(0, leaf1.GetOutput())
leaf2 = vtkSphereSource()
leaf2.SetCenter(1.75, 2.5, 0)
leaf2.SetRadius(1.5)
leaf2.Update()
branch.SetBlock(1, leaf2.GetOutput())
leaf3 = vtkSphereSource()
leaf3.SetCenter(4, 0, 0)
leaf3.SetRadius(2)
leaf3.Update()
root.SetBlock(1, leaf3.GetOutput())
output.DeepCopy(root)
A follow-up question is: how can I set the names of the branches and leaves (that appears in the data hierarchy) ?
It is possible to specify a name for the Meta Data of each branch or leaf as shown below.
branch.GetMetaData(0).Set(vtk.vtkCompositeDataSet.NAME(), 'sphere1')
branch.GetMetaData(1).Set(vtk.vtkCompositeDataSet.NAME(), 'sphere2')
root.GetMetaData(1).Set(vtk.vtkCompositeDataSet.NAME(), 'sphere3')
1 Like