Stl to .mesh

Pages: 12
I'm looking for some code to convert the stl file to .mesh or ascii. I would be grateful if someone can share that in case if he has.
Last edited on
You should be more specific so that others don't have to do research that you probably already know.

Are you talking about the .mesh format used by Medit?
For example, looks like this?
https://people.sc.fsu.edu/~jburkardt/data/medit/cube86.mesh

For the .stl format, is it the binary or plaintext format?

And ascii is character encoding, not a "format" for CAD, so what exactly do you mean by ascii?

Anyway, I found this GitHub project, which claims it can convert a variety of different mesh formats:
https://github.com/nschloe/meshio
Online Mesh Converter:
https://www.meshconvert.com/

FYI, from a C++ programming standpoint any mention of STL without any qualifiers (hint, stereolighography) is gonna make people think you want to something to a Standard Template Library file. I know that is what I thought until I did a 'net search.

Doing a 'net search isn't all that hard to MAYBE find what you are looking for.
https://duckduckgo.com/?q=stl+file+to+.mesh&t=ffsb&ia=web
@Ganado it's ASCII. I don't know about medit but I am looking for .mesh.
@George P thanks for your answer. I already knew about the mesh converter. but I'm specifically looking for c++ code for this purpose. I know I shouldn't be asking about code here but I have no idea about this stuff in c++. That's why I'm looking for an example code.
Last edited on
.STL file format uses either a binary or textual representation.

In your reply to @Ganado you said your .STL data is already represented textually.

You listed ASCII as an acceptable output format.
What is the ASCII format in this context?
Last edited on
convert the stl file to .mesh


An STL file gives the set of triangles that make up the surface of an object. I once had a go at writing a generator here: https://www.cplusplus.com/forum/beginner/278645/#msg1203789

A .mesh file contains an entire finite-element or finite-volume 3-d mesh. That might well be generated from the surface information, but it isn't the surface.

They aren't the same type of thing. Are you sure that you don't just want a mesh-generator?
Last edited on
@lastchance It can be .msh or any other compatible formats which fluent can read them.
Last edited on
The consensus on the web seems to be that you use ANSYS SpaceClaim to read the STL file and convert it into a geometry that ANSYS Fluent (or any other ANSYS product) can use. See, e.g.,
https://forum.ansys.com/discussion/193/how-to-work-with-stl-file
or
https://www.youtube.com/watch?v=DxLW6KIVgdk

I don't use Fluent.
@lastchance thanks for your answer. It's been a long time that I haven't used fluent but now due to some reasons I have to. I tried the Spaceclaim but fluent failed to read the case. I think during the conversion from stl to .msh or solid geometry something is going worng. For example once I was working with finite element and I was trying to open the mesh in paraview but after reading the mesh paraview crashed everytime. Then I found out that there are some miscamputing with connectivity. I thinks something similar is happening here.
Last edited on
In case if someone want to try I upload the file in box and I'm sharing the link.https://app.box.com/s/iti9pus6dqd1wblcwlrkhnxrh6vl6ysb
Well, I don't use Fluent, but I do use StarCCM+.

I created an STL file of my own, imported it into StarCCM+, meshed it (with StarCCM+'s built-in mesher) and then exported it as Ensight Gold format, which I could successfully view in Paraview.

However, when I tried to do the same with your file it didn't like it. Are you sure that your STL file is correct (closed boundary with no discontinuities etc.)?
I was thinking about the same but I don't know how to check it. As far as I can check in SpaceClaim it includes 4 bodies merged together. How can I check for any discontinuties? I used online mesh converter before posting this question, then converted it to .obj. Then opened the file with notepad and copied the data into a file in notepad++ (.msh). That's how I got .msh at the beginning. When I was looking at the data it looked like normal but I can't say there is no discontinuties.
Last edited on
it includes 4 bodies merged together


That's ominous. The chances of the surface triangles lining up correctly are pretty slim.

You might have a "mend the surface" option in SpaceClaim. StarCCM+ does, but I simply don't know it well enough to use it.

You would be better merging the bodies in whatever was used to create the file before outputting to STL.
Last edited on
It has something to check the faces if everything is fine. I tried that and there was no error. Thanks for your answers.
The problem is not about discontinuties. I have another stl file and it's. Msh file. I'm able to run .msh in Fluent. But when I try to convert the stl to .msh and run in Fluent it fails. So the problem is the way I'm converting the stl file.
Last edited on
@OP
On close inspection of the file you shared it appears to be a .stl file prepared in Blender - that's what it plainly says, despite being generally binary-like or whatever vs plain text.
So, importing it into Blender and displaying it with the shader turned off it appears as a triangulated surface mesh in 3D. It's fully rotatable etc etc.
Export that as a .obj file and the .obj file is readable as text, and fully displayable in Blender
As far as discontinuities are concerned, keep in mind blender is graphics software and is not concerned about discontinuities that might/probably will affect a Fluent analysis. i.e. Blender is probably not a good way to develop 3D analytical models.
@Cplusc,

The problem is not your conversion method - it is the original STL file.

I can load it and view it in StarCCM+ - the surface triangulation is clear:
https://imgur.com/WwCwarq

If you then run an error check on it then 8 free edges are reported. This prevents me from meshing it directly.

I can (sort of) mend it with StarCCM+'s surface wrapper. Then I can successfully mesh it and export it. .msh is not an option to me, so I used Ensight Gold. Here it is with the exported mesh viewed in Paraview:
https://imgur.com/eyfZq53


So, you need to fix your STL file, ideally in whatever software you used to create it in the first place, or, failing that, with whatever ANSYS's software will allow you to mend it with.
@lastchance I can see the surface in SpaceClaim and paraview as well. In SpaceClaim when I run an error check I'll get the errors as you mentioned. I doubt that the problem is stl file, because for one specific geometry I have both stl and .mesh. when I run .msh in Fluent it's fine but when I convert the stl to .msh it doesn't work in Fluent. I tried this with other cases as well.
@Cplusc,
You misread my answer. I am not viewing the STL file in Paraview: I am viewing an Ensight Gold file that contains a volume mesh (not just the surface) created once I managed to circumvent the errors in the STL file and hence create a mesh from it.

You need to fix your STL file.
Pages: 12