Hello!
Currently I am working on a code, which shoud allow me to import a geometry via a .step file and further edit it with simple actions. I am trying to cut a hole in the form of a cylinder into my geometry. I guess it is not possible to edit a OCCGeometry, so maybe there’s a workaround?
Here’s my code:
from netgen.occ import *
from ngsolve import *
# Import geometry
step_geo = OCCGeometry(str(file_step))
# Define position and direction of shaft
start_point_shaft = Pnt(0, -e, w/2)
direction_shaft = Vec(0, 0, -1)
# Create shaft
shaft = Cylinder(gp_Ax2(start_point_shaft, direction_shaft), r, w)
shaft.faces.Max(Y).name = 'inside'
# Create final geometry
geo = step_geo - OCCGeometry(shaft)
# Visaulize geometry
Draw(geo)
The error occurs when trying to subtract the “shaft” from the rest of the geometry.
Thank you very much for your help!
Hey!
Thank you very much for your quick reply. Your Code was correct and now my programm doesn’t show me any errors. But for some reason, the hole is not displayed and I can’t seem to get the meshing done. It just meshes forever and never finishes.
I attached the used STEP-File and here’s an updated version of my code. Maybe you can help me out again? Thank you very much and have a nice day!
Just for information: Before I want to import the STEP-File, my code is giving out parameters to SOLIDWORKS and automatically saves the resulting model as a STEP-File. Therefore the Diameter D is equal to the outer Diameter of the model.
from netgen.occ import *
from ngsolve import *
import pyngcore as ngcore
# Diameter and radius of bearing [m]
D = 30 * 10**-3
R = D / 2
# Diameter and radius of shaft [m]
d = 28 * 10**-3
r = d / 2
# Width [m]
w = 20 * 10**-3
# Excentricity [-/m]
epsilon = 0.5
e = epsilon * (R - r)
# maximal mesh size [m]
max_mesh = 1 * 10**-3
# number of processors [-]
numProc = 8
# Import geometry
step_geo = OCCGeometry(str(file_step))
# Get geometry as shape
shape = step_geo.shape
# Define position and direction of shaft
start_point_shaft = Pnt(0, -e, w/2)
direction_shaft = Vec(0, 0, 1)
# Create shaft
shaft = Cylinder(gp_Ax2(start_point_shaft, direction_shaft), r, w)
shaft.faces.Max(Y).name = 'inside'
# Create final geometry
geo = OCCGeometry(shape - shaft)
# Visaulize geometry
Draw(geo)
print('\nGeometry finished\n')
# Generate mesh
ngcore.SetNumThreads(numProc)
with ngcore.TaskManager():
mesh = Mesh(geo.GenerateMesh(maxh=max_mesh))
# Visualize mesh
Draw(mesh)
print('\nSuccess! Finished Executing!\n')
I guess that means, that the units of imported STEP-files get interpretet as meters no matter what they really are. Is that correct?
Because I just checked and the SolidWorks model is in mm and should be okay.
Nevertheless it’s working now and instead of upscaling the shaft, I downscaled the imported geometry. This way there should not be a problem with the remaining units!