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

Keith Sloan keith at sloan-home.co.uk
Fri Jul 3 20:38:55 CEST 2020


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 )



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://onelab.info/pipermail/gmsh/attachments/20200703/166d5dc4/attachment-0001.html>


More information about the gmsh mailing list