# Problem in generating a vtk file with UNSTRUCTURED\_GRID and reading it in Paraview

**URL:** https://discourse.paraview.org/t/problem-in-generating-a-vtk-file-with-unstructured-grid-and-reading-it-in-paraview/7819
**Category:** ParaView Support
**Created:** [August 14, 2021, 1:03pm UTC](https://discourse.paraview.org/t/problem-in-generating-a-vtk-file-with-unstructured-grid-and-reading-it-in-paraview/7819 "2021-08-14T13:03:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Diogo\_Cecilio](https://discourse.paraview.org/user_avatar/discourse.paraview.org/diogo_cecilio/32/7368_2.png) [@Diogo\_Cecilio](https://discourse.paraview.org/u/Diogo_Cecilio)
#### Post date: [August 14, 2021, 1:03pm UTC](https://discourse.paraview.org/t/problem-in-generating-a-vtk-file-with-unstructured-grid-and-reading-it-in-paraview/7819/1 "2021-08-14T13:03:12Z")

</div>

I have this .vtk file that I have created for a single quadratic hexahedron element (cube):

# vtk DataFile Version 3.0

File generated from DClib  
ASCII

DATASET UNSTRUCTURED\_GRID  
POINTS 20 float  
0 0 0  
1 0 0  
1 1 0  
0 1 0  
0 0 1  
1 0 1  
1 1 1  
0 1 1  
0.5 0 0  
1 0.5 0  
0.5 1 0  
0 0.5 0  
0 0 0.5  
1 0 0.5  
1 1 0.5  
0 1 0.5  
0.5 0 1  
1 0.5 1  
0.5 1 1  
0 0.5 1  
CELLS 1 20  
20 0 1 2 3 4 5 6 7 8 9 10 11 16 17 18 19 12 13 14 15  
CELL\_TYPES 1  
25

When I open It in Paraview the clube is missing a side. What I’am missing here?

 ![Screenshot_20210814-100038](https://discourse.paraview.org/uploads/default/original/2X/7/7ca11926fd3a634b3563f3da89a84fd6277a1cc4.png)

---

<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: [August 14, 2021, 2:42pm UTC](https://discourse.paraview.org/t/problem-in-generating-a-vtk-file-with-unstructured-grid-and-reading-it-in-paraview/7819/2 "2021-08-14T14:42:55Z")

</div>

It seems to be correct when written as follows:

> # vtk DataFile Version 5.1  
> vtk output  
> ASCII  
> DATASET UNSTRUCTURED\_GRID  
> POINTS 20 float  
> 0 0 0  
> 1 0 0  
> 1 1 0  
> 0 1 0  
> 0 0 1  
> 1 0 1  
> 1 1 1  
> 0 1 1  
> 0.5 0 0  
> 1 0.5 0  
> 0.5 1 0  
> 0 0.5 0  
> 0.5 0 1  
> 1 0.5 1  
> 0.5 1 1  
> 0 0.5 1  
> 0 0 0.5  
> 1 0 0.5  
> 1 1 0.5  
> 0 1 0.5  
> CELLS 2 20  
> OFFSETS vtktypeint64  
> 0 20  
> CONNECTIVITY vtktypeint64  
> 0 1 2 3 4 5 6 7 8  
> 9 10 11 12 13 14 15 16 17  
> 18 19  
> CELL\_TYPES 1  
> 25

 ![quadratic_hex](https://discourse.paraview.org/uploads/default/original/2X/c/c7215d9ab915b029ee3a1f86037706d32a7726f9.png)

---

<div class="post-metadata">

### Author: ![Diogo\_Cecilio](https://discourse.paraview.org/user_avatar/discourse.paraview.org/diogo_cecilio/32/7368_2.png) [@Diogo\_Cecilio](https://discourse.paraview.org/u/Diogo_Cecilio)
#### Post date: [August 14, 2021, 4:32pm UTC](https://discourse.paraview.org/t/problem-in-generating-a-vtk-file-with-unstructured-grid-and-reading-it-in-paraview/7819/3 "2021-08-14T16:32:41Z")

</div>

Kyoshimi,

indeed it works. But why is necessary create two cells? As far as I know the documentation dont mention it for te hexahedron.

EDIT:

solved here:

> <https://stackoverflow.com/questions/68776437/problem-in-generating-a-vtk-file-with-unstructured-grid-and-reading-it-in-paravi>

---

<div class="post-metadata">

### Author: ![Andrew\_Maclean](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@Andrew\_Maclean](https://discourse.paraview.org/u/Andrew_Maclean)
#### Post date: [August 16, 2021, 6:46am UTC](https://discourse.paraview.org/t/problem-in-generating-a-vtk-file-with-unstructured-grid-and-reading-it-in-paraview/7819/4 "2021-08-16T06:46:26Z")

</div>

Please have a look at [https://kitware.github.io/vtk-examples/site/Python/GeometricObjects/LinearCellDemo](https://kitware.github.io/vtk-examples/site/Python/GeometricObjects/LinearCellDemo)

You only need 8 points:

```nohighlight
# vtk DataFile Version 5.1
vtk output
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 8 float
0 0 0 1 0 0 0 1 0 
1 1 0 0 0 1 1 0 1 
0 1 1 1 1 1 
CELLS 2 8
OFFSETS vtktypeint64
0 8 
CONNECTIVITY vtktypeint64
0 1 2 3 4 5 6 7 
CELL_TYPES 1
11

```

If you want to write out the unstructured grid, just drop in these lines before the ` return ug` line for each cell type:

```auto
    ug_writer = vtk.vtkUnstructuredGridWriter()
    ug_writer.SetInputData(ug)
    ug_writer.SetFileName('x.vtk')
    ug_writer.SetFileTypeToASCII()
    ug_writer.Write()

```
