# vtk-example, output to main window instead of new window

**URL:** https://discourse.paraview.org/t/vtk-example-output-to-main-window-instead-of-new-window/9332
**Category:** ParaView Support
**Tags:** python, vtk
**Created:** [April 2, 2022, 2:50pm UTC](https://discourse.paraview.org/t/vtk-example-output-to-main-window-instead-of-new-window/9332 "2022-04-02T14:50:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bigfooted](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bigfooted/32/6347_2.png) [@bigfooted](https://discourse.paraview.org/u/bigfooted)
#### Post date: [April 2, 2022, 2:50pm UTC](https://discourse.paraview.org/t/vtk-example-output-to-main-window-instead-of-new-window/9332/1 "2022-04-02T14:50:02Z")

</div>

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](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”

```auto
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])

```

---

<div class="post-metadata">

### Author: ![bigfooted](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bigfooted/32/6347_2.png) [@bigfooted](https://discourse.paraview.org/u/bigfooted)
#### Post date: [April 2, 2022, 3:23pm UTC](https://discourse.paraview.org/t/vtk-example-output-to-main-window-instead-of-new-window/9332/2 "2022-04-02T15:23:23Z")

</div>

I’d like to add that I get the same error message when I try this example:  
[https://www.paraview.org/Wiki/ParaView/Simple\_ParaView\_3\_Python\_Filters#Producing\_An\_Unstructured\_Grid\_(Source)](https://www.paraview.org/Wiki/ParaView/Simple_ParaView_3_Python_Filters#Producing_An_Unstructured_Grid_(Source))  
( 27.536s) [paraview] vtkPolyData.cxx:1074 ERR| vtkPolyData (0x173b4790): Invalid cell type: 12

edit: using ParaView-5.10.1-MPI-Linux-Python3.9-x86\_64

---

<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: [April 4, 2022, 12:14am UTC](https://discourse.paraview.org/t/vtk-example-output-to-main-window-instead-of-new-window/9332/3 "2022-04-04T00:14:18Z")

</div>

After changing **Output Data Set** from **vtkPolyData** to **vtkUnstructuredGrid** and modifying the **script** as follows, it works without any problem. I hope this helps you.

 ![programmable_source](https://discourse.paraview.org/uploads/default/original/2X/e/e813baa5902bacb4672e2aac92cbd00aae51c532.png)

```python
import vtk

pdo = self.GetOutput()

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.VTK_HEXAHEDRON, 8, pts[0])
pdo.InsertNextCell(vtk.VTK_HEXAHEDRON, 8, pts[1])
pdo.InsertNextCell(vtk.VTK_TETRA, 4, pts[2][:4])
pdo.InsertNextCell(vtk.VTK_TETRA, 4, pts[3][:4])
pdo.InsertNextCell(vtk.VTK_POLYGON, 6, pts[4][:6])
pdo.InsertNextCell(vtk.VTK_TRIANGLE_STRIP, 6, pts[5][:6])
pdo.InsertNextCell(vtk.VTK_QUAD, 4, pts[6][:4])
pdo.InsertNextCell(vtk.VTK_TRIANGLE, 3, pts[7][:3])
pdo.InsertNextCell(vtk.VTK_TRIANGLE, 3, pts[8][:3])
pdo.InsertNextCell(vtk.VTK_LINE, 2, pts[9][:2])
pdo.InsertNextCell(vtk.VTK_LINE, 2, pts[10][:2])
pdo.InsertNextCell(vtk.VTK_VERTEX, 1, pts[11][:1])

```

---

<div class="post-metadata">

### Author: ![bigfooted](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bigfooted/32/6347_2.png) [@bigfooted](https://discourse.paraview.org/u/bigfooted)
#### Post date: [April 4, 2022, 6:31am UTC](https://discourse.paraview.org/t/vtk-example-output-to-main-window-instead-of-new-window/9332/4 "2022-04-04T06:31:24Z")

</div>

Oh great, thanks! Yes, I saw that my output was set to PolyData!
