Loading and merging STL files using python script


Is it possible to do the following using a python script. I am able to do it using GUI.

  1. load a binary STL file,
  2. create a volume mesh,
  3. merge similarly created multiple volume mesh.

Thanks for helping.


Hi Saurabh,

you can merge meshes with a little Python programming, here is a similar usecase:



Hello Joachim,

Thanks a lot for the quick response. I followed the link you suggested, however, I am getting following error during the creation of volume mesh.:

netgen.libngpy._meshing.NgException: Stop meshing since boundary mesh is overlapping

Could you please suggest a way to resolve this issue?


Maybe something with the index conversion went wrong.

It’s best to draw the merged meshes (surface and or volume). For that you have to wrap the Netgen-mesh into an NGSolve mesh first:

import ngsolve as ngs
ngsmesh = ngs.Mesh(netgenmesh)
Draw (ngsmesh)

You can also post your py-codes and meshes.


Hello Joachim,

Thanks again for your response. I am still getting the issue of overlapping elements. I have attached two STL files and the python script I am using to merge them. I can mesh and merge these STL files using the GUI, but not with python.

It would be great if you could take a look at the files and guide me in sorting the issue.


Attachment: mesh3.py

Attachment: t1g.stl

Attachment: t2g.stl