# convert .stl fomat to .vtk format (XML VTU format and legacy ASCII format)

**URL:** https://discourse.vtk.org/t/convert-stl-fomat-to-vtk-format-xml-vtu-format-and-legacy-ascii-format/8280
**Category:** Support
**Created:** [April 12, 2022, 9:16am UTC](https://discourse.vtk.org/t/convert-stl-fomat-to-vtk-format-xml-vtu-format-and-legacy-ascii-format/8280 "2022-04-12T09:16:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hye00525](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hye00525/32/4904_2.png) [@hye00525](https://discourse.vtk.org/u/hye00525)
#### Post date: [April 12, 2022, 9:16am UTC](https://discourse.vtk.org/t/convert-stl-fomat-to-vtk-format-xml-vtu-format-and-legacy-ascii-format/8280/1 "2022-04-12T09:16:32Z")

</div>

Hello,  
I’m trying to visualize my .stl file using [glvis](https://glvis.org/) library (for using [mfem](https://mfem.org/) )  
.stl format is not supported in mfem, so I tried converting it to .vtk format. (using the following code)

```auto
 vtkSmartPointer<vtkSTLReader> stlReader__ = vtkSmartPointer<vtkSTLReader>::New();
stlReader__->SetFileName("D:\\C3.stl");
stlReader__->Update();

vtkSmartPointer<vtkPolyDataWriter> vtkWriter = vtkSmartPointer<vtkPolyDataWriter>::New();
vtkWriter->SetFileName("D:\\c3.vtk");
vtkWriter-> SetInputData(stlReader__-> GetOutput());
vtkWriter->Update();

```

The vtk format conversion was successful, but when I run it in glvis, the following error occurs.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/6/6c8ea1ba337f23d0292ff26b69bfb189d5bd9fed.png)

```auto
Verification failed: (major_vtk_version >= 2 && major_vtk_version <= 4) is false:
 --> Unsupported VTK format
 ... in function: void __cdecl mfem::Mesh::Loader(class std::basic_istream<char,struct std::char_traits<char> > &,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)
 ... in file: E:\mfem-master\mesh\mesh.cpp:4052

```

After searching, it says that I need to change my vtk file to ASCII VTK version 4, or XML VTK. Is there a way to change using vtk code without using ParaView? (I have to solve it inside vtk project without using Paraview.

[related issue link](https://github.com/mfem/mfem/issues/2347)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [April 12, 2022, 11:05am UTC](https://discourse.vtk.org/t/convert-stl-fomat-to-vtk-format-xml-vtu-format-and-legacy-ascii-format/8280/2 "2022-04-12T11:05:21Z")

</div>

You can write older version of the file with this:

[https://vtk.org/doc/nightly/html/classvtkDataWriter.html#a2e473c06cc1dc75bb63ff29c21933290acd12becdbb6a4dd1cd39930e28433000](https://vtk.org/doc/nightly/html/classvtkDataWriter.html#a2e473c06cc1dc75bb63ff29c21933290acd12becdbb6a4dd1cd39930e28433000)
