Here is a vtk example that I would like to modify to run in the paraview main window using a programmable source:
https://gitlab.kitware.com/vtk/vtk-examples/-/blob/master/src/Python/UnstructuredGrid/UGrid.py
I can put this entire python code in a programmable source and it will create a new independent window with the mesh shown. I would like this output to go directly to the main paraview window instead, but I do not know exactly how to modify it to get the output correct
below is a partially working example, it shows part of the mesh and gives the error “vtkPolyData: invalid cell type: 12”
from vtkmodules.vtkCommonDataModel import (
VTK_HEXAHEDRON,
VTK_LINE,
VTK_POLYGON,
VTK_QUAD,
VTK_TETRA,
VTK_TRIANGLE,
VTK_TRIANGLE_STRIP,
VTK_VERTEX,
vtkUnstructuredGrid
)
pdo = self.GetPolyDataOutput()
x = [[0, 0, 0], [1, 0, 0], [2, 0, 0], [0, 1, 0], [1, 1, 0], [2, 1, 0], [0, 0, 1], [1, 0, 1], [2, 0, 1], [0, 1, 1],[1, 1, 1], [2, 1, 1], [0, 1, 2], [1, 1, 2], [2, 1, 2], [0, 1, 3], [1, 1, 3], [2, 1, 3], [0, 1, 4], [1, 1, 4],[2, 1, 4], [0, 1, 5], [1, 1, 5], [2, 1, 5], [0, 1, 6], [1, 1, 6], [2, 1, 6]]
pts = [[0, 1, 4, 3, 6, 7, 10, 9], [1, 2, 5, 4, 7, 8, 11, 10], [6, 10, 9, 12, 0, 0, 0, 0],[8, 11, 10, 14, 0, 0, 0, 0], [16, 17, 14, 13, 12, 15, 0, 0], [18, 15, 19, 16, 20, 17, 0, 0],[22, 23, 20, 19, 0, 0, 0, 0], [21, 22, 18, 0, 0, 0, 0, 0], [22, 19, 18, 0, 0, 0, 0, 0],[23, 26, 0, 0, 0, 0, 0, 0], [21, 24, 0, 0, 0, 0, 0, 0], [25, 0, 0, 0, 0, 0, 0, 0]]
print("size = ",len(x), len(pts))
points = vtk.vtkPoints()
for i in range(0, len(x)):
points.InsertPoint(i, x[i])
pdo.SetPoints(points)
#pdo = vtk.vtkUnstructuredGrid()
pdo.Allocate(100)
pdo.InsertNextCell(VTK_HEXAHEDRON, 8, pts[0])
pdo.InsertNextCell(VTK_HEXAHEDRON, 8, pts[1])
pdo.InsertNextCell(VTK_TETRA, 4, pts[2][:4])
pdo.InsertNextCell(VTK_TETRA, 4, pts[3][:4])
pdo.InsertNextCell(VTK_POLYGON, 6, pts[4][:6])
pdo.InsertNextCell(VTK_TRIANGLE_STRIP, 6, pts[5][:6])
pdo.InsertNextCell(VTK_QUAD, 4, pts[6][:4])
pdo.InsertNextCell(VTK_TRIANGLE, 3, pts[7][:3])
pdo.InsertNextCell(VTK_TRIANGLE, 3, pts[8][:3])
pdo.InsertNextCell(VTK_LINE, 2, pts[9][:2])
pdo.InsertNextCell(VTK_LINE, 2, pts[10][:2])
pdo.InsertNextCell(VTK_VERTEX, 1, pts[11][:1])