Convert .xml file to .stl or other format using meshio


493
views
0
6 months ago by
Ovais  
Hi there ,

I am trying to convert mesh in .xml format to .stl or any other format acceptable as input in Salome. From other posts on this forum i have come to know that  meshio can be used for this conversion.

There is no documentation available on the meshio github/bitbucket page. Can anyone suggest what sort of coding would be required for the conversion. My mesh contains half a  million nodes hence i cant list them all the way it has been mentioned on the meshio page as example code (https://pypi.python.org/pypi/meshio)

Regards.  
Community: FEniCS Project
I've been trying to do something similar. You can save the mesh as a .pvd doing

Vtkfile= File('mymesh.pvd')

Vtkfile << mesh

Youmay be able to export the mesh into other formats from paraview. If you are working with meshio, it looks like it can already read in the dolfin xml file, per the first demo. That should automatically read in the file and have the nodes and cells organized in the way it needs to write to another format.
written 6 months ago by Ryan W  
Thanks for response. I have tried with paraview but paraview doesnt convert files to .stl format.
About meshio  , i am trying to make it work but gettting error. As under:-
-----------------------------------------------------------------------------------------------------
from dolfin import*
import meshio

meshio-convert mesh115.xml output.stl
written 6 months ago by Ovais  
However i am getting followng  error
-------------------------------------------------------------------------------------------------------
meshio-convert input.xml output.stl
^
SyntaxError: invalid syntax

on the other hand meshio is working with following simple code :-
from dolfin import*
import meshio
import numpy as np

points = np.array([[0.0, 0.0, 0.0],[0.0, 1.0, 0.0],[0.0, 0.0, 1.0],])
cells = {'triangle': np.array([[0, 1, 2]]) }
meshio.write('foo1.vtk', points, cells,)
written 6 months ago by Ovais  

1 Answer


2
6 months ago by
Ryan W  
Since meshio is a python library, you'd need to run the file as a python file.

a .py file with the following code should work:

import meshio

#Read in your .xml file, where "args.infile" is replaced by your mesh file name

my_xml_file = 'MyFileName.xml'

#This line reads in the points and cells from your xml file, 
#And returns them as the objects on the left of the = sign
points, cells, point_data, cell_data, field_data = meshio.read(my_xml_file)

#Write the stl file

my_stl_file = 'MyFileName.stl'

meshio.write(my_stl_file, points, cells)​
thanx! after some change i have converted files to .stl using similar code that u have suggested (as under)
--------------------------------------------------------------------------------------
from dolfin import*
import meshio

points, cells, point_data, cell_data, field_data = meshio.read('mesh115.xml')
meshio.write('mesh_vent.msh', points, cells)
written 6 months ago by Ovais  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »