# vtkStringArray is not properly added when vtkUnstructuredGrid is outputted as PVTU file

**URL:** https://discourse.vtk.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/1684
**Category:** Development
**Created:** [September 3, 2019, 7:47pm UTC](https://discourse.vtk.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/1684 "2019-09-03T19:47:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vchan1186](https://discourse.vtk.org/user_avatar/discourse.vtk.org/vchan1186/32/851_2.png) [@vchan1186](https://discourse.vtk.org/u/vchan1186)
#### Post date: [September 3, 2019, 7:47pm UTC](https://discourse.vtk.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/1684/1 "2019-09-03T19:47:45Z")

</div>

I am trying to add a `vtkStringArray` to a `vtkUnstructuredGrid` using the `AddArray` method. The string array shows up in the spreadsheet view for serial vtu files, but does not appear when loading a pvtu file in ParaView.

I add a string array by building on the Polyhedron example from [https://lorensen.github.io/VTKExamples/site/Cxx/GeometricObjects/Polyhedron/](https://lorensen.github.io/VTKExamples/site/Cxx/GeometricObjects/Polyhedron/)

The source code for adding a string array to a polyhedron and writing out to a serial vtu file is shown below:

```auto
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkDataArray.h>
#include <vtkDataSetMapper.h>
#include <vtkIdList.h>
#include <vtkNamedColors.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyhedron.h>
#include <vtkSmartPointer.h>
#include <vtkStringArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkXMLUnstructuredGridWriter.h>

int main(int, char *[])
{
  // Create a Polyhedron (cube)
  vtkIdType pointIds[8] = {0, 1, 2, 3, 4, 5, 6, 7};

  vtkSmartPointer<vtkPoints> points =
    vtkSmartPointer<vtkPoints>::New();
  points->InsertNextPoint(-1.0,-1.0,-1.0);
  points->InsertNextPoint( 1.0,-1.0,-1.0);
  points->InsertNextPoint( 1.0, 1.0,-1.0);
  points->InsertNextPoint(-1.0, 1.0,-1.0);
  points->InsertNextPoint(-1.0,-1.0, 1.0);
  points->InsertNextPoint( 1.0,-1.0, 1.0);
  points->InsertNextPoint( 1.0, 1.0, 1.0);
  points->InsertNextPoint(-1.0, 1.0, 1.0);

  // Define faces according to point IDs
  vtkSmartPointer<vtkCellArray> faces =
    vtkSmartPointer<vtkCellArray>::New();
  vtkIdType face0[4] = {0, 3, 2, 1};
  vtkIdType face1[4] = {0, 4, 7, 3};
  vtkIdType face2[4] = {4, 5, 6, 7};
  vtkIdType face3[4] = {5, 1, 2, 6};
  vtkIdType face4[4] = {0, 1, 5, 4};
  vtkIdType face5[4] = {2, 3, 7, 6};

  faces->InsertNextCell(4, face0);
  faces->InsertNextCell(4, face1);
  faces->InsertNextCell(4, face2);
  faces->InsertNextCell(4, face3);
  faces->InsertNextCell(4, face4);
  faces->InsertNextCell(4, face5);

  vtkSmartPointer<vtkUnstructuredGrid> ugrid =
    vtkSmartPointer<vtkUnstructuredGrid>::New();
  ugrid->SetPoints(points);
  ugrid->InsertNextCell(VTK_POLYHEDRON, 8, pointIds,
                        6, faces->GetPointer());

  // Create string scalar
  vtkSmartPointer<vtkStringArray> string_data = 
    vtkSmartPointer<vtkStringArray>::New();

  string_data->SetName("A_String_Array");
  string_data->InsertNextValue("Hello");

  // Add string array to unstructured grid
  ugrid->GetCellData()->AddArray(string_data);

  // Here write out serial vtu
  vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
    vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
  writer->SetInputData(ugrid);
  writer->SetFileName("polyhedron.vtu");
  writer->SetDataModeToAscii();
  writer->Update();
  writer->Write();

```

For the pvtu file, I simply replace the writer in the above code with:

```auto
  vtkSmartPointer<vtkXMLPUnstructuredGridWriter> writer =
    vtkSmartPointer<vtkXMLPUnstructuredGridWriter>::New();
  writer->SetInputData(ugrid);
  writer->SetFileName("parallel_polyhedron.pvtu");
  writer->SetNumberOfPieces(1);
  writer->SetStartPiece(0);
  writer->SetEndPiece(0);
  writer->SetDataModeToAscii();
  writer->Update();
  writer->Write();

```

and replace the `#include <vtkXMLUnstructuredGridWriter.h>` to `#include <vtkXMLPUnstructuredGridWriter.h>`.

When loading the vtu files for both cases (“polyhedron.vtu” and “parallel\_polyhedron\_0.vtu”), the string value `"Hello"` show up in the spreadsheet view under `"test_name"`. However, when the pvtu file (“parallel\_polyhedron.pvtu”) is loaded, the string value is blank under `"test_name"` in the spreadsheet view.

How can I add a string array such that its string value shows up properly in the spreadsheet view when loading the pvtu file?

Thank you,  
Victor

---

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dcthomp/32/60_2.png) [@dcthomp](https://discourse.vtk.org/u/dcthomp)
#### Post date: [November 19, 2019, 12:38pm UTC](https://discourse.vtk.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/1684/2 "2019-11-19T12:38:58Z")

</div>

Hi @vchan1186, I think this is more of a ParaView issue than a VTK issue. Here:

[https://discourse.paraview.org/c/paraview-support](https://discourse.paraview.org/c/paraview-support)

might be a better place for this post.

---

<div class="post-metadata">

### Author: ![vchan1186](https://discourse.vtk.org/user_avatar/discourse.vtk.org/vchan1186/32/851_2.png) [@vchan1186](https://discourse.vtk.org/u/vchan1186)
#### Post date: [December 1, 2019, 3:55am UTC](https://discourse.vtk.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/1684/3 "2019-12-01T03:55:02Z")

</div>

Thanks David, I have reposted this in the ParaView discourse:  
[https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087)
