Skip to content

Instantly share code, notes, and snippets.

@rnagasam
Created January 6, 2018 22:00
Show Gist options
  • Save rnagasam/d830e649c3f088119dbfdad4acbde596 to your computer and use it in GitHub Desktop.
Save rnagasam/d830e649c3f088119dbfdad4acbde596 to your computer and use it in GitHub Desktop.
FreeCAD scripting -- create a mesh using GMSH from within FreeCAD
# Use GMSH from within FreeCAD
# useful for performing any
# kind of scripting with the
# FEM module
# Require : FreeCAD > 0.17
# : GMSH
# Required imports
import FreeCAD
import Part
import ObjectsFem
from femmesh import gmshtools # <FreeCAD_src>/Mod/Fem/femmesh/gmshtools.py
# create the document
doc = App.newDocument()
# add a box to the document
doc.addObject("Part::Feature","Shape")
doc.Shape.Shape = Part.makeBox(1,1,1)
# setup
ObjectsFem.makeMeshGmsh(doc, "Mesh")
doc.Mesh.Part = doc.Shape
# create the mesh; using gmshtools lets
# you do all of this without having to
# open FreeCAD
g = gmshtools.GmshTools(doc.Mesh)
g.create_mesh()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment