Selective Mesh on step file

Hi guys,
I would like to know if it is possible to mesh only a face from a 3d step file.
All faces have unique name, and we can read them with mesh.GetBoundaries().
If it isn’t possible, i would like to know how to print boundary’s vertices.

Hi Thomas,
I can suggest the following plans, if one fits I can get into more details:

  1. extract the OCC-face (as a shape) from the OCC geometry, and mesh only that one
  2. mesh the whole geometry, iterate over all boundary elements, check the bc-label of that element, and get all vertices of that boundary element (uses Python loops)
  3. define fes=H1(mesh, order=1) finite element space, and ask for the RegionDofs of the boundary-region of interest. You will get a BitArray (all loops are executed in fast C++ code)

best, Joachim

I think the best is the first one.
Will it work if I only have netgen.occ ?
Thanks a lot for your answer.

We create a cube, name the faces and store it as step-file

from netgen.occ import *

shape = Box((0,0,0), (1,1,1)) = "default"
shape.faces.Max(X).name = "righttop"
shape.faces.Max(Z).name = "righttop"

We reload the step-file as Netgen-OCCGeometry, and extract the OCC-shape. We can extract the faces using the netgen.occ - Python wrapper to OCC. Finally, we make a new Netgen-OCCGeometry:

geo = OCCGeometry("cube.stp")
shape2 = geo.shape
for f in shape2.faces:
    print (

rt = Glue (shape2.faces["righttop"])
partgeo = OCCGeometry(rt)

and mesh it:

from ngsolve import *
from ngsolve.webgui import Draw   # using jupyter drawing

mesh = Mesh(partgeo.GenerateMesh(maxh=0.2))
Draw (mesh);


I’ve just tried it, and it doesn’t work for me.
Print ( returns all the faces’s name but the mesh makes no cells or elements.
(Geometrie is another STEP file, but it do the same as cube.stp)

This is my code with your recommandations :

from netgen.occ import *
from ngsolve import *
import pyvista as pv

geo = OCCGeometry(“Geometrie.stp”)
shape2 = geo.shape
for f in shape2.faces:
print (

rt = Glue (shape2.faces[“Face3”])
partgeo = OCCGeometry(rt)

mesh = Mesh(partgeo.GenerateMesh(maxh=100))

VTKOutput object

vtk = VTKOutput(ma=mesh,


grid =‘Face3.vtu’)
plotter = pv.Plotter()
plotter.add_mesh(grid, opacity=0.5)

The jupyter library never works for me, so I use pyvista and the VTK Output command instead.

Thanks for your help

It work,
it was the fault of the VTKOutput.
I change for a STL Export and all working fine.
Thanks Again !