[Gmsh] 3D Volume from 2D Mesh via python program

Christophe Geuzaine cgeuzaine at uliege.be
Fri Jul 3 20:56:56 CEST 2020


Dear Keith,

Please send something that we can test; in this case a working script together with the STL file. Or if the STL file is confidential, at least send a log of the terminal output. And if you don't have output on a terminal, then use the logger API - see e.g. tutorial/python/t16.py.

Christophe


> On 3 Jul 2020, at 20:38, Keith Sloan <keith at sloan-home.co.uk> wrote:
> 
> Hi I am trying to remesh an STL file to create a Tetrahderon.
> 
> My code looks like based on info on the web
> 
> SaimaSafdar commented on 2 Sep 2019 • 
> edited by nschloe 
> I used the gmsh-api for python https://gitlab.onelab.info/gmsh/gmsh/blob/master/README.txt
> The code I used is below for the gmsh-api
> 
> import math
> import gmsh_api
> import gmsh_api.gmsh as gmsh
> 
> gmsh.initialize()
> gmsh.option.setNumber("General.Terminal", 1)
> gmsh.option.setNumber("Mesh.Algorithm", 8);
> gmsh.option.setNumber("Mesh.CharacteristicLengthMin", 1);
> gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 2);
> gmsh.option.setNumber("Mesh.Optimize",1)
> gmsh.option.setNumber("Mesh.QualityType",2);
> 
> gmsh.merge("C:/2_FuzzyClassification/brainmodel/brainModelscriptacvd.stl")
> n = gmsh.model.getDimension()
> s = gmsh.model.getEntities(n)
> l = gmsh.model.geo.addSurfaceLoop([s[i][1] for i in range(len(s))])
> gmsh.model.geo.addVolume([l])
> print("Volume added")
> gmsh.model.geo.synchronize()
> 
> gmsh.model.mesh.generate(3)
> gmsh.write("C:/2_FuzzyClassification/brainmodel/example.msh")
> gmsh.finalize()
> 
> 
> 
> My Code
> 
> def meshObjSTL(obj, dim) :
>     obj.Mesh.write('/tmp/transfer.stl')
>     bbox = obj.Mesh.BoundBox
>     ml = maxCord(bbox) / 10
>     print('Mesh length : '+str(ml))
>     gmsh.option.setNumber("Mesh.Algorithm",8)
>     gmsh.option.setNumber("Mesh.CharacteristicLengthMax", ml)
>     gmsh.option.setNumber("Mesh.CharacteristicLengthFromCurvature", ml)
>     gmsh.option.setNumber("Mesh.CharacteristicLengthFromPoints", ml)
>     gmsh.option.setNumber("Mesh.Optimize",1)
>     gmsh.option.setNumber("Mesh.QualityType",2)
>     gmsh.merge('/tmp/transfer.stl')
>     n = gmsh.model.getDimension()
>     s = gmsh.model.getEntities(n)
>     l = gmsh.model.geo.addSurfaceLoop([s[i][1] for i in range(len(s))])
>     gmsh.model.geo.addVolume([l])
>     print("Volume added")
>     gmsh.model.geo.synchronize()
>     gmsh.model.mesh.generate(dim)
>     print('Mesh Generated '+str(dim))
>     gmsh.model.mesh.renumberNodes()
> 
> But crashes with no output ( Code is part of a FreeCAD workbench )
> 
> 
> 
> 
> 
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh

— 
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science 
http://www.montefiore.ulg.ac.be/~geuzaine






More information about the gmsh mailing list