# Can .vtp files hold multiple data fields or just one?

**URL:** https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245
**Category:** ParaView Support
**Tags:** vtk
**Created:** [November 13, 2023, 6:18pm UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245 "2023-11-13T18:18:47Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 13, 2023, 6:18pm UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/1 "2023-11-13T18:18:48Z")

</div>

The following Python code converts a `.vtk` file to a `.vtp` file for viewing using e.g. Glance:

```py
# Read VTK
reader = vtkStructuredGridReader()
reader.SetFileName(filename + ".vtk")

# Extract surface
surface_filter = vtkDataSetSurfaceFilter()
surface_filter.SetInputConnection(reader.GetOutputPort())

clean_filter = vtkCleanPolyData()
clean_filter.SetInputConnection(surface_filter.GetOutputPort())

# Save output to a VTP file
writer = vtkXMLPolyDataWriter()
writer.SetFileName(filename + ".vtp")
writer.SetInputConnection(clean_filter.GetOutputPort())
writer.Write()

```

This works fine, but when I have multiple fields, such as `Directivity_dBi` and `Directivity_linear`:

```py
# vtk DataFile Version 3.0
3D Farfield
ASCII
DATASET STRUCTURED_GRID
DIMENSIONS 1 91 181
POINTS 16471 double
-1.000000e+00 1.000000e+00 4.006663e+01
4.257683e-01 1.000000e+00 4.003194e+01
1.847900e+00 1.000000e+00 3.993014e+01
...
-1.000000e+00 1.000000e+00 -1.754531e+01

POINT_DATA 16471
SCALARS Directivity_dBi double 1
LOOKUP_TABLE default
7.775559e+00
7.765758e+00
7.738521e+00
...
-1.634019e+01
-1.635408e+01
-1.633920e+01

SCALARS Directivity_linear double 1
LOOKUP_TABLE default
5.991781e+00
5.978273e+00
5.940897e+00
...
2.322637e-02
2.315217e-02
2.323166e-02

```

…it only seems to write `Directivity_dBi` to the `.vtp` file, ignoring `Directivity_linear` completely. I am able to view `pattern_1_2400000000.0.vtk` and both Directivity entries are there:

 ![Screenshot 2023-11-13 at 8.09.44 PM](https://discourse.paraview.org/uploads/default/original/2X/b/b8a8dc9a67409095f53afa3bd8d1b85812bcf486.jpeg)

* * *

Attached both files for reference (input `.vtk` and output `.vtp`):

- **VTK:** [pattern\_1\_2400000000.0.vtk](https://discourse.paraview.org/uploads/short-url/pyFb2VaTynEPxozVE94PL9jcmxg.vtk) (1.1 MB)
- **VTP:** [pattern\_1\_2400000000.0.vtp](https://discourse.paraview.org/uploads/short-url/aNzwW8Lmde4cetsbWY4DI9ZDICH.vtp) (687.8 KB)

* * *

Is there anything I could modify to ensure both data fields are passed?

---

<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 14, 2023, 8:55am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/2 "2023-11-14T08:55:48Z")

</div>

> Can .vtp files hold multiple data fields or just one?

Of course they can (generated with ParaView directly):  
[pattern\_1\_2400000000.0\_kw.vtp](https://discourse.paraview.org/uploads/short-url/b3NZU16GyKf8KKNQe2QpMNe2lOI.vtp) (1.0 MB)

I don’t see anything wrong in your VTK code though. Inspect the outputs of each of your filter to see why the array is disapearing.

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 14, 2023, 12:28pm UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/3 "2023-11-14T12:28:20Z")

</div>

> [@mwestphal](#):
>
> I don’t see anything wrong in your VTK code though. Inspect the outputs of each of your filter to see why the array is disapearing.

Printing `surface_filter` doesn’t show much (or at least I’m not sure if there’s anything interesting to extract):

```auto
vtkDataSetSurfaceFilter (0x118645190)
  Debug: Off
  Modified Time: 136
  Reference Count: 2
  Registered Events: (none)
  Executive: 0x600002168500
  ErrorCode: Undefined error: 0
  Information: 0x60000393c5a0
  AbortExecute: Off
  Progress: 0
  Progress Text: (None)
  PieceInvariant: 0
  PassThroughCellIds: Off
  PassThroughPointIds: Off
  OriginalCellIdsName: vtkOriginalCellIds
  OriginalPointIdsName: vtkOriginalPointIds
  NonlinearSubdivisionLevel: 1
  FastMode: 0
  Delegation: 0

```

And removing `clean_filter` doesn’t fix the problem, so that filter is definitely not the issue. Are you able to reproduce this when running the script using the `vtk` module?

Perhaps another question I should ask in advance is this: if I also wish to assign different coordinate points, i.e. this part:

```py
DATASET STRUCTURED_GRID
DIMENSIONS 1 91 181
POINTS 16471 double
-1.000000e+00 1.000000e+00 4.006663e+01
4.257683e-01 1.000000e+00 4.003194e+01
1.847900e+00 1.000000e+00 3.993014e+01
...

```

to the second set of the scalar data, can VTP support this? That’s my ultimate goal, so that the coordinates also change when the scalar values are different.

Another alternative would be to produce 2 `.vtk` files (which I can handle easily), but I’m not sure how we could merge them into a single `.vtp`.

---

<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 14, 2023, 2:17pm UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/4 "2023-11-14T14:17:05Z")

</div>

> [@WarinSpace\_Game](#):
>
> Printing `surface_filter` doesn’t show much

Print the _output_ of the filter instead 🙂

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 14, 2023, 3:12pm UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/5 "2023-11-14T15:12:22Z")

</div>

`surface_filter.GetOutput()` returns:

```py
vtkPolyData (0x13868c3e0)
  Debug: Off
  Modified Time: 357
  Reference Count: 2
  Registered Events: (none)
  Information: 0x60000133b300
  Data Released: False
  Global Release Data: Off
  UpdateTime: 0
  Field Data:
    Debug: Off
    Modified Time: 354
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
  Number Of Points: 0
  Number Of Cells: 0
  Cell Data:
    Debug: Off
    Modified Time: 357
    Reference Count: 1
    Registered Events:
      Registered Observers:
        vtkObserver (0x60000397f990)
          Event: 33
          EventName: ModifiedEvent
          Command: 0x6000014703c0
          Priority: 0
          Tag: 1
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 1 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 1 1 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 1 1 1 )
    Scalars: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
    Tangents: (none)
    RationalWeights: (none)
    HigherOrderDegrees: (none)
  Point Data:
    Debug: Off
    Modified Time: 356
    Reference Count: 1
    Registered Events:
      Registered Observers:
        vtkObserver (0x60000397f960)
          Event: 33
          EventName: ModifiedEvent
          Command: 0x6000014703c0
          Priority: 0
          Tag: 1
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 1 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 1 1 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 1 1 1 )
    Scalars: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
    Tangents: (none)
    RationalWeights: (none)
    HigherOrderDegrees: (none)
  Bounds:
    Xmin,Xmax: (1, -1)
    Ymin,Ymax: (1, -1)
    Zmin,Zmax: (1, -1)
  Compute Time: 0
  Editable: false
  Number Of Points: 0
  Point Coordinates: 0x0
  PointLocator: 0x0
  CellLocator: 0x0
  Number Of Vertices: 0
  Number Of Lines: 0
  Number Of Polygons: 0
  Number Of Triangle Strips: 0
  Number Of Pieces: 1
  Piece: -1
  Ghost Level: 0
  CellsBounds:
    Xmin,Xmax: (1, -1)
    Ymin,Ymax: (1, -1)
    Zmin,Zmax: (1, -1)
  CellsBounds Time: 0

```

---

<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 14, 2023, 4:18pm UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/6 "2023-11-14T16:18:29Z")

</div>

> [@WarinSpace\_Game](#):
>
> ```auto
> Number Of Points: 0
> Number Of Cells: 0
> 
> ```

After updating the filter.

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 14, 2023, 11:01pm UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/7 "2023-11-14T23:01:34Z")

</div>

After `surface_filter.Update()`:

```py
vtkPolyData (0x1116476f0)
  Debug: Off
  Modified Time: 560
  Reference Count: 2
  Registered Events: (none)
  Information: 0x600000d4fe40
  Data Released: False
  Global Release Data: Off
  UpdateTime: 561
  Field Data:
    Debug: Off
    Modified Time: 513
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
  Number Of Points: 16471
  Number Of Cells: 16200
  Cell Data:
    Debug: Off
    Modified Time: 560
    Reference Count: 1
    Registered Events:
      Registered Observers:
        vtkObserver (0x60000270f900)
          Event: 33
          EventName: ModifiedEvent
          Command: 0x600000a086e0
          Priority: 0
          Tag: 1
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
    Copy Tuple Flags: ( 1 1 1 1 1 1 1 1 1 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 1 0 1 1 1 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 1 1 1 )
    Scalars: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
    Tangents: (none)
    RationalWeights: (none)
    HigherOrderDegrees: (none)
  Point Data:
    Debug: Off
    Modified Time: 558
    Reference Count: 1
    Registered Events:
      Registered Observers:
        vtkObserver (0x60000270f8d0)
          Event: 33
          EventName: ModifiedEvent
          Command: 0x600000a086e0
          Priority: 0
          Tag: 1
    Number Of Arrays: 1
    Array 0 name = Directivity_dBi
    Number Of Components: 1
    Number Of Tuples: 16471
    Copy Tuple Flags: ( 1 1 1 1 1 1 1 1 1 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 1 0 1 1 1 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 1 1 1 )
    Scalars:
      Debug: Off
      Modified Time: 555
      Reference Count: 1
      Registered Events: (none)
      Name: Directivity_dBi
      Data type: double
      Size: 16471
      MaxId: 16470
      NumberOfComponents: 1
      Information: 0x0
      Name: Directivity_dBi
      Number Of Components: 1
      Number Of Tuples: 16471
      Size: 16471
      MaxId: 16470
      LookupTable: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
    Tangents: (none)
    RationalWeights: (none)
    HigherOrderDegrees: (none)
  Bounds:
    Xmin,Xmax: (-31.173, 29.0485)
    Ymin,Ymax: (-29.3445, 31.424)
    Zmin,Zmax: (-19.2903, 40.0666)
  Compute Time: 574
  Editable: false
  Number Of Points: 16471
  Point Coordinates: 0x600001b0b600
  PointLocator: 0x0
  CellLocator: 0x0
  Number Of Vertices: 0
  Number Of Lines: 0
  Number Of Polygons: 16200
  Number Of Triangle Strips: 0
  Number Of Pieces: 1
  Piece: 0
  Ghost Level: 0
  CellsBounds:
    Xmin,Xmax: (-31.173, 29.0485)
    Ymin,Ymax: (-29.3445, 31.424)
    Zmin,Zmax: (-19.2903, 40.0666)
  CellsBounds Time: 575

```

Looks like only `Directivity_dBi` is written and `Directivity_linear` is ignored.

---

<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 15, 2023, 8:19am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/8 "2023-11-15T08:19:47Z")

</div>

> [@WarinSpace\_Game](#):
>
> `Number Of Arrays: 1`

Then check the output of the reader itself.

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 15, 2023, 8:28am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/9 "2023-11-15T08:28:15Z")

</div>

`reader.Update()` and then `reader.GetOutput()` returns:

```py
vtkStructuredGrid (0x110fa1bc0)
  Debug: Off
  Modified Time: 380
  Reference Count: 2
  Registered Events: (none)
  Information: 0x6000003707e0
  Data Released: False
  Global Release Data: Off
  UpdateTime: 385
  Field Data:
    Debug: Off
    Modified Time: 350
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
  Number Of Points: 16471
  Number Of Cells: 16200
  Cell Data:
    Debug: Off
    Modified Time: 358
    Reference Count: 1
    Registered Events:
      Registered Observers:
        vtkObserver (0x600002930fc0)
          Event: 33
          EventName: ModifiedEvent
          Command: 0x600000424690
          Priority: 0
          Tag: 1
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 1 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 1 1 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 1 1 1 )
    Scalars: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
    Tangents: (none)
    RationalWeights: (none)
    HigherOrderDegrees: (none)
  Point Data:
    Debug: Off
    Modified Time: 380
    Reference Count: 1
    Registered Events:
      Registered Observers:
        vtkObserver (0x600002930f90)
          Event: 33
          EventName: ModifiedEvent
          Command: 0x600000424690
          Priority: 0
          Tag: 1
    Number Of Arrays: 1
    Array 0 name = Directivity_dBi
    Number Of Components: 1
    Number Of Tuples: 16471
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 1 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 1 1 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 1 1 1 )
    Scalars:
      Debug: Off
      Modified Time: 377
      Reference Count: 1
      Registered Events: (none)
      Name: Directivity_dBi
      Data type: double
      Size: 16472
      MaxId: 16470
      NumberOfComponents: 1
      Information: 0x0
      Name: Directivity_dBi
      Number Of Components: 1
      Number Of Tuples: 16471
      Size: 16472
      MaxId: 16470
      LookupTable: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
    Tangents: (none)
    RationalWeights: (none)
    HigherOrderDegrees: (none)
  Bounds:
    Xmin,Xmax: (-31.173, 29.0485)
    Ymin,Ymax: (-29.3445, 31.424)
    Zmin,Zmax: (-19.2903, 40.0666)
  Compute Time: 399
  Editable: false
  Number Of Points: 16471
  Point Coordinates: 0x600001528510
  PointLocator: 0x0
  CellLocator: 0x0
  Dimensions: (1, 91, 181)
  Extent: 0, 0, 0, 90, 0, 180
)

```

So it seems that the problem is in the reading itself rather than the filters.

---

<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 15, 2023, 8:31am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/10 "2023-11-15T08:31:17Z")

</div>

> [@WarinSpace\_Game](#):
>
> `Number Of Arrays: 1`

Looks like the reader is providing only a single array. Try calling `ReadAllScalarsOn()` and `ReadAllSVectorsOn()` before updating.

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 15, 2023, 8:34am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/11 "2023-11-15T08:34:05Z")

</div>

Yes! That finally fixed it, thanks a lot!

That helps. Do we also know whether different points can be used for the second array?

> [@WarinSpace\_Game](#):
>
> Perhaps another question I should ask in advance is this: if I also wish to assign different coordinate points, i.e. this part:
> 
> ```py
> DATASET STRUCTURED_GRID
> DIMENSIONS 1 91 181
> POINTS 16471 double
> -1.000000e+00 1.000000e+00 4.006663e+01
> 4.257683e-01 1.000000e+00 4.003194e+01
> 1.847900e+00 1.000000e+00 3.993014e+01
> ...
> 
> ```
> 
> to the second set of the scalar data, can VTP support this? That’s my ultimate goal, so that the coordinates also change when the scalar values are different.
> 
> Another alternative would be to produce 2 `.vtk` files (which I can handle easily), but I’m not sure how we could merge them into a single `.vtp`.

---

<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 15, 2023, 8:38am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/12 "2023-11-15T08:38:57Z")

</div>

> That helps. Do we also know whether different points can be used for the second array?

You should either use another .vtp enterely or store the secondary points as a 3-component point data and switch the points using a dedicated filter (can be done with a calculator).

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 15, 2023, 9:27am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/13 "2023-11-15T09:27:12Z")

</div>

Is there any way this could be done in Glance? My goal is to easily toggle between the two by simply changing the selection from the dropdown:

 ![Screenshot 2023-11-15 at 11.24.21 AM](https://discourse.paraview.org/uploads/default/original/2X/a/a68e995a36f7bd0b6aa38c8ea394ed805a59ed28.png)

which obviously changes the color, but not the coordinates of the points.

I could obviously export 2 separate .vtp files, but I’d prefer to toggle between the two using a dropdown instead of displaying it as if it is a completely different set of data.

---

<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 15, 2023, 9:31am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/14 "2023-11-15T09:31:52Z")

</div>

I’m quite sure this cannot be done in glance out of the box.

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [November 16, 2023, 3:13am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/15 "2023-11-16T03:13:03Z")

</div>

If you use time as a fake dimension, you can export your data and view it in glance so you can switch between 1 mesh and another but the format will have to be the “web export (.vtkjs)” from ParaView.

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 27, 2023, 6:14am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/16 "2023-11-27T06:14:37Z")

</div>

Thank you folks - I ended up using separate VTPs and everything works fine.

* * *

Quick question: what’s the proper way to close off the VTK reader? I seem to be getting some `'ascii' codec can't decode byte 0xe2 in position 9403: ordinal not in range(128)` errors which _only_ come up after my VTK operations, so it seems that some file readers might be interfering and need to be properly closed off:

```py
# This works
with open("some_file.txt", "r") as file:
    file_content = file.read()

# Read VTK
reader = vtkStructuredGridReader()
reader.SetFileName(filename + ".vtk")

# Extract surface
surface_filter = vtkDataSetSurfaceFilter()
surface_filter.SetInputConnection(reader.GetOutputPort())

clean_filter = vtkCleanPolyData()
clean_filter.SetInputConnection(surface_filter.GetOutputPort())

# Save output to a VTP file
writer = vtkXMLPolyDataWriter()
writer.SetFileName(filename + ".vtp")
writer.SetInputConnection(clean_filter.GetOutputPort())
writer.Write()

# This fails
with open("some_file.txt", "r") as file:
    file_content = file.read()

```

---

<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 27, 2023, 8:25am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/17 "2023-11-27T08:25:35Z")

</div>

You can try deleting the writer and the reader, but that looks like a bug to me.

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 27, 2023, 10:23am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/18 "2023-11-27T10:23:41Z")

</div>

I tried `del reader, writer` but the issue persists.

---

<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 27, 2023, 10:31am UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/19 "2023-11-27T10:31:26Z")

</div>

Call the python garbage collector ?

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [November 27, 2023, 12:06pm UTC](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245/20 "2023-11-27T12:06:03Z")

</div>

Same thing happens after calling `gc.collect()` after the `del`.

[Next page](https://discourse.paraview.org/t/can-vtp-files-hold-multiple-data-fields-or-just-one/13245.md?page=2)
