get points and connectivity from vtkunstructuredgrid

Hi all,
I would like to write the points and connectivity information from an unstructuredgrid to a file using a python plugin. I’m wondering if I’m doing the right thing. My data comes from a multiblock and I first get the block containing the unstructuredgrid and put it in ugrid.

To access the points and connectivity I basically do this below, and I’m wondering if this is really the best way to do it.

        # this gets the connectivity  
        print("###   get the connectivity   ###")
        celldata = ugrid.GetCells()
        pts = vtk.vtkIdList()
        for i in range(celldata.GetNumberOfCells()):
         celldata.GetCellAtId(i,pts)
         print("number of ids = ",pts.GetNumberOfIds())
         for j in range(pts.GetNumberOfIds()):
           print(pts.GetId(j))

        print("###   get the points   ###")
        pntdata = ugrid.GetPoints()
        for p in range(pntdata.GetNumberOfPoints()):
            print(pntdata.GetPoint(p))

My goal is to write data to a file in the format (celltype, listofconnectivities, id):

NELEM= 293
9 0 6 66 22 0
5 217 231 252 1
etc.
NPOIN= 257
0.0 0.0 0.0
0.5 0.0 0.0
etc.

For element types (triangles, quadrilaterals etc.) you may use vtkUnstructuredGrid::GetCellTypesArray() for connectivity information you can access the internal array using vtkUnstructuredGrid::GetCells() and then see this detailed description about the layout of the data in this array.

If your goal is just to convert vtk files to .su2 meshes you can also check meshio

Hi Christos,
Thanks for the pointers. I have used meshio with pyvista for su2 meshes (outside of paraview), but haven’t tried the paraview plugin yet. However, meshio does not preserve the names of the multiblock meshes (the boundary names that is), so there is still some additional work to be done even when using meshio.