# Usage of setFileVersion method

**URL:** https://discourse.vtk.org/t/usage-of-setfileversion-method/10861
**Category:** Support
**Tags:** file-formats
**Created:** [March 2, 2023, 2:28pm UTC](https://discourse.vtk.org/t/usage-of-setfileversion-method/10861 "2023-03-02T14:28:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ackhyon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/c6cbf5/32.png) [@Ackhyon](https://discourse.vtk.org/u/Ackhyon)
#### Post date: [March 2, 2023, 2:28pm UTC](https://discourse.vtk.org/t/usage-of-setfileversion-method/10861/1 "2023-03-02T14:28:00Z")

</div>

Hi there,

First of all, thanks for providing this very useful toolkit!

I have a question regarding the way to write legacy PolyData files at the old 4.2 format: I am trying to call the SetFileVersion method of the vtkDataWriter object but my mesh seems to still be saved at format 5.1 and I don’t understand what is wrong in my code.

I am using vtk-9.2.5 on MacOS Monterey (12.6).

Please find below a minimal reproducer.

```auto
cat > vtkDataSetWriter.cxx <<EOF
#include <vtkCellArray.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkQuad.h>
#include <vtkCellArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetWriter.h>

int main(int, char*[])
{
  // Create a grid
  auto dataSet = vtkSmartPointer<vtkUnstructuredGrid> :: New();
  auto points = vtkSmartPointer<vtkPoints> :: New();
  auto cellArray = vtkSmartPointer<vtkCellArray> :: New();

  // Add points
  points->InsertNextPoint(0, 0, 0);
  points->InsertNextPoint(1, 0, 0);
  points->InsertNextPoint(0, 1, 0);
  points->InsertNextPoint(1, 1, 0);

  dataSet->SetPoints(points);

  // Add quad
  auto quad = vtkSmartPointer<vtkQuad> :: New();

  quad->GetPointIds()->SetId(0, 0);
  quad->GetPointIds()->SetId(1, 1);
  quad->GetPointIds()->SetId(2, 2);
  quad->GetPointIds()->SetId(3, 3);

  cellArray->InsertNextCell(quad);
  dataSet->SetCells(VTK_QUAD,cellArray);

  // Write file
  vtkNew<vtkDataSetWriter> writer;

#if VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 1
  // Set writer version 4.2
  cout << "Force saving at format 4.2" << std::endl;
  writer->SetFileVersion(42);
#endif

  writer->SetFileName("output.vtk");
  writer->SetInputData(dataSet);
  writer->Write();

  return EXIT_SUCCESS;
}
EOF

```

```auto
cat > CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(vtkDataSetWriter)

find_package(VTK COMPONENTS
  CommonCore
  CommonDataModel
  IOLegacy
)

if (NOT VTK_FOUND)
  message(FATAL_ERROR "XMLStructuredGridWriter: Unable to find the VTK build folder.")
endif()

# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(vtkDataSetWriter MACOSX_BUNDLE vtkDataSetWriter.cxx )
  target_link_libraries(vtkDataSetWriter PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
  TARGETS vtkDataSetWriter
  MODULES ${VTK_LIBRARIES}
)
EOF

```

When executing the code, the `Force saving at format 4.2` output is printed in my prompt but  
the output file I obain contains the `# vtk DataFile Version 5.1` header line and keywords not recognized by reader 4.2.

Thanks by advance for any help,  
Best Regards,

---

<div class="post-metadata">

### Author: ![Francois\_Mazen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/francois_mazen/32/3290_2.png) [@Francois\_Mazen](https://discourse.vtk.org/u/Francois_Mazen)
#### Post date: [March 17, 2023, 6:41pm UTC](https://discourse.vtk.org/t/usage-of-setfileversion-method/10861/2 "2023-03-17T18:41:25Z")

</div>

Hi @Ackhyon

Indeed, this looks like an issue, and I’ve reported it here: [https://gitlab.kitware.com/vtk/vtk/-/issues/18854](https://gitlab.kitware.com/vtk/vtk/-/issues/18854)

The fix will likely to follow and in the meantime, as a workaround, you can use the `vtkUnstructuredGridWriter` directly instead of the `vtkDataSetWriter`.

Thanks for this report!

Best Regards,

François

---

<div class="post-metadata">

### Author: ![Francois\_Mazen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/francois_mazen/32/3290_2.png) [@Francois\_Mazen](https://discourse.vtk.org/u/Francois_Mazen)
#### Post date: [March 29, 2023, 11:14am UTC](https://discourse.vtk.org/t/usage-of-setfileversion-method/10861/3 "2023-03-29T11:14:39Z")

</div>

The problem has just been fixed in the master version of VTK.

[https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/10084](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10084)

---

<div class="post-metadata">

### Author: ![Ackhyon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/c6cbf5/32.png) [@Ackhyon](https://discourse.vtk.org/u/Ackhyon)
#### Post date: [March 31, 2023, 7:06am UTC](https://discourse.vtk.org/t/usage-of-setfileversion-method/10861/4 "2023-03-31T07:06:37Z")

</div>

Hi,

Thanks for your help and for your feedback!

Best Regards,
