How to read step file in netgen python script

Hello there,

I just wonder if there is a way of using OCC in the netgen python script. The tutorial only shows using CSG geometry and others. I want to be able to read step file into python script and run the netgen using python file. Thanks a lot for the assistance!

Best regards,
Blueze

Hi,

there is a module NgOCC which has a function LoadOCCGeometry. Here is a small example

from netgen.NgOCC import *

geo = LoadOCCGeometry('screw.step')
mesh = geo.GenerateMesh()
# mesh.Save('screw.vol')

from ngsolve import *
Draw(Mesh(mesh))

Make sure to use the newest release (v6.2.1710).
This module isn’t frequently used from your side. If you have any problems, feel free to ask.

Best regards,
Christoph

Hello Chris,

Thank you very much for the assistance. Do you know to how to heal geometry in python script after importing step file?

Best regards,
Blueze

Hi Blueze,

I just added a function to heal the geometry after loading. So you can call .Heal() on a OCCGeometry. It is in our git repo now and a merge request is submitted.

Are you using and self compiled or an installer version of Netgen?
After the merge request is accepted, the change is pushed to github should be in the nightly installer the day after.

Best regards,
Christoph

Hello Chris,

Thank you very much for this updated information. I build the netgen using cmake according to
https://ngsolve.org/docu/latest/install/installlinux.html

Will I need to git update and then reinstall according to the link above, once the netgen github merge request is completed? Thanks a lot!

Best regards,
Blueze

Hi Blueze,

exactly, you just have to follow the “Keep it up to date” section in the link you wrote.

You are welcome. If you need another functionality from the gui in the python interface, just ask and we will try to add it.

Best regards,
Christoph

Hello Chris,

Thank you very much for the information.

Best regards,
Blueze

Just exploring your viewer.
Really like it.
Even found 1651-how-could-i-import-step-file-as-topods-shape#4462 to convert the occgeometry into a shape so I can view the imported step file prior to creating a mesh.

What I also like is that in the viewer I can mouse-click on a face or edge and the face/edge ID is shown.
Would it be possible to get this information available in my python code?
And would it also be possible for the VERTICES?

And if so, I would also like to have (x,y,z) coordinates related to the face/edge/vertex ID?