Skip to content

Commit b35b89f

Browse files
authored
Merge pull request #22 from CadQuery/get-imprinted
Created get_imprinted_gmsh method
2 parents f967ac5 + 7152e1d commit b35b89f

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

assembly_mesh_plugin/plugin.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,12 @@ def assembly_to_gmsh(self, mesh_path="tagged_mesh.msh"):
182182
gmsh.finalize()
183183

184184

185-
def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"):
185+
def get_imprinted_gmsh(self):
186186
"""
187-
Exports an imprinted assembly to capture conformal meshes.
187+
Allows the user to get a gmsh object from the assembly, with the assembly being imprinted.
188188
"""
189189

190+
# Initialize gmsh and create a new model
190191
gmsh.initialize()
191192
gmsh.option.setNumber("General.Terminal", 0)
192193
gmsh.model.add("assembly")
@@ -208,7 +209,6 @@ def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"):
208209
cq.occ_impl.assembly.imprint(self)
209210
)
210211

211-
print(imprinted_solids_with_orginal_ids)
212212
for solid, id in imprinted_solids_with_orginal_ids.items():
213213
# Add the current solid to the mesh
214214
# Work-around for a segfault with in-memory passing of OCCT objects
@@ -297,6 +297,17 @@ def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"):
297297

298298
gmsh.model.occ.synchronize()
299299

300+
return gmsh
301+
302+
303+
def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"):
304+
"""
305+
Exports an imprinted assembly to capture conformal meshes.
306+
"""
307+
308+
# Turn this assembly into a imprinted gmsh object
309+
gmsh = get_imprinted_gmsh(self)
310+
300311
gmsh.model.mesh.field.setAsBackgroundMesh(2)
301312

302313
gmsh.model.mesh.generate(3)
@@ -310,3 +321,4 @@ def assembly_to_imprinted_gmsh(self, mesh_path="tagged_mesh.msh"):
310321
cq.Assembly.saveToGmsh = assembly_to_gmsh # Alias name that works better on cq.Assembly
311322
cq.Assembly.getTaggedGmsh = get_tagged_gmsh
312323
cq.Assembly.assemblyToImprintedGmsh = assembly_to_imprinted_gmsh
324+
cq.Assembly.getImprintedGmsh = get_imprinted_gmsh

tests/smoke_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ def test_nested_cubes():
2424
assert len(surfaces) == 18
2525

2626

27+
def test_imprinted_assembly_mesh():
28+
"""
29+
Tests to make sure that the imprinted assembly mesh works correctly with tagging.
30+
"""
31+
32+
# Create the basic assembly
33+
assy = generate_test_cross_section()
34+
35+
# Convert eh assembly to an imprinted GMSH mesh
36+
gmsh = assy.getImprintedGmsh()
37+
38+
# Make sure we have the correct number of surfaces
39+
surfaces = gmsh.model.getEntities(2)
40+
assert len(surfaces) == 56
41+
42+
2743
def test_basic_assembly():
2844
"""
2945
Tests to make sure that the most basic assembly works correctly with tagging.

0 commit comments

Comments
 (0)