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

**URL:** https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087
**Category:** Development
**Created:** [December 1, 2019, 3:54am UTC](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087 "2019-12-01T03:54:50Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![vchan1186](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@vchan1186](https://discourse.paraview.org/u/vchan1186)
#### Post date: [December 1, 2019, 3:54am UTC](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087/1 "2019-12-01T03:54:50Z")

</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: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [December 2, 2019, 8:59am UTC](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087/2 "2019-12-02T08:59:26Z")

</div>

please share your dataset.

---

<div class="post-metadata">

### Author: ![vchan1186](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@vchan1186](https://discourse.paraview.org/u/vchan1186)
#### Post date: [December 2, 2019, 8:15pm UTC](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087/3 "2019-12-02T20:15:24Z")

</div>

Hi Mathieu,  
The datasets are attached. Note that the string value `"Hello"` shows up under `"A_String_Array"` for the “polyhedron.vtu” and “parallel\_polyhedron\_0.vtu” files in the spreadsheet view (make sure to choose the cell attribute). When loading the “parallel\_polyhedron.pvtu” file, the string value is blank under `"A_String_Array"`.  
Thank you,  
Victor[polyhedron.vtu](https://discourse.paraview.org/uploads/short-url/5AqWoPbgqy1tjUBItTDSFWVYN6v.vtu) (1.8 KB) [parallel\_polyhedron\_0.vtu](https://discourse.paraview.org/uploads/short-url/pb93QDwr5QIyqtG1EhvEeVP2RSO.vtu) (2.0 KB) [parallel\_polyhedron.pvtu](https://discourse.paraview.org/uploads/short-url/qRgn7Z84UeN3SptbyYr8WwHPpYe.pvtu) (401 Bytes)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [December 3, 2019, 10:25am UTC](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087/4 "2019-12-03T10:25:35Z")

</div>

Looks like a small bug with the parallel reader. I’ve opened an issue here:  
[https://gitlab.kitware.com/paraview/paraview/issues/19501](https://gitlab.kitware.com/paraview/paraview/issues/19501)

---

<div class="post-metadata">

### Author: ![vchan1186](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@vchan1186](https://discourse.paraview.org/u/vchan1186)
#### Post date: [April 1, 2020, 9:05pm UTC](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087/5 "2020-04-01T21:05:23Z")

</div>

Hi Matthieu,  
No one seems to be interested in fixing this bug. Could you give me some guidance on how to fix this issue? Once fixed, I can submit a pull request.  
Thank you,  
Victor

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 8, 2020, 5:21am UTC](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087/6 "2020-04-08T05:21:29Z")

</div>

One would need to investigate it by debugging the parallel reader. I may try to do it if I find the time.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [November 13, 2020, 9:57am UTC](https://discourse.paraview.org/t/vtkstringarray-is-not-properly-added-when-vtkunstructuredgrid-is-outputted-as-pvtu-file/3087/7 "2020-11-13T09:57:14Z")

</div>

I did not find the time sadly.
