Skip to content

Commit abb9988

Browse files
committed
Added a readme example that was also made into a test, and restructured a bit
1 parent bcc717a commit abb9988

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,40 @@ import cadquery_assembly_mesh_plugin.plugin
2626
You can then tag faces in each of the assembly parts and create your asembly. To export the assembly to a mesh file, you do the following.
2727

2828
```python
29-
your_assembly.assemblyToGmsh(mesh_path="tagged_planar_coil.msh")
29+
your_assembly.assemblyToGmsh(mesh_path="tagged_mesh.msh")
3030
```
3131

3232
Normal tag names lead to a physical group with the assembly part name prefixed. So a tag name of `inner-bottom` on an assembly part with the name `steel_plate` will be `steel_plate_inner-bottom`
3333

3434
By prefixing a tag with the `~` character, the part name is ignored, which allows for tagging of a multi-material
3535
physical group. For instance, tagging multiple faces with `~contact-with-casing` will produce a physical group with the name `contact-with-casing` that includes all those faces, even if they belong to different parts/solids.
3636

37+
Below is a simple example.
38+
39+
```python
40+
import cadquery as cq
41+
import cadquery_assembly_mesh_plugin.plugin
42+
import gmsh
43+
44+
shell = cq.Workplane("XY").box(50, 50, 50)
45+
shell = shell.faces(">Z").workplane().rect(21, 21).cutThruAll()
46+
shell.faces(">X[-2]").tag("inner-right")
47+
shell.faces("<X[-2]").tag("~in_contact")
48+
49+
# Create the insert
50+
insert = cq.Workplane("XY").box(20, 20, 50)
51+
insert.faces("<X").tag("~in_contact")
52+
insert.faces(">X").tag("outer-right")
53+
54+
assy = cq.Assembly()
55+
assy.add(shell, name="shell", loc=cq.Location(cq.Vector(0, 0, 0)), color=cq.Color("red"))
56+
assy.add(insert, name="insert", loc=cq.Location(cq.Vector(0, 0, 0)), color=cq.Color("blue"))
57+
58+
assy.assemblyToGmsh(mesh_path="tagged_mesh.msh")
59+
```
60+
61+
The resulting `.msh` file should have three physical groups in it. The `in_contact` group should include the faces from both the shell and the insert.
62+
3763
## Tests
3864

3965
These tests are also run in Github Actions, and the meshes which are generated can be viewed as artifacts on the successful `tests` Actions there.

tests/sample_coils.py renamed to tests/sample_assemblies.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
import cadquery as cq
22

33

4+
def generate_simple_nested_boxes():
5+
"""
6+
Generates the simplest assembly case where two boxes are nested inside each other.
7+
"""
8+
9+
# Create the outter shell
10+
shell = cq.Workplane("XY").box(50, 50, 50)
11+
shell = shell.faces(">Z").workplane().rect(21, 21).cutThruAll()
12+
shell.faces(">X[-2]").tag("inner-right")
13+
shell.faces("<X[-2]").tag("~in_contact")
14+
15+
# Create the insert
16+
insert = cq.Workplane("XY").box(20, 20, 50)
17+
insert.faces("<X").tag("~in_contact")
18+
insert.faces(">X").tag("outer-right")
19+
20+
assy = cq.Assembly()
21+
assy.add(
22+
shell, name="shell", loc=cq.Location(cq.Vector(0, 0, 0)), color=cq.Color("red")
23+
)
24+
assy.add(
25+
insert,
26+
name="insert",
27+
loc=cq.Location(cq.Vector(0, 0, 0)),
28+
color=cq.Color("blue"),
29+
)
30+
31+
return assy
32+
33+
434
def generate_test_cross_section():
535
"""
636
Generates a basic cross-section to verify that the tagged faces are crossing over

tests/smoke_test.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import assembly_mesh_plugin.plugin
2-
from sample_coils import generate_test_cross_section, generate_assembly
2+
from tests.sample_assemblies import (
3+
generate_simple_nested_boxes,
4+
generate_test_cross_section,
5+
generate_assembly,
6+
)
7+
8+
9+
def test_basic_assembly():
10+
"""
11+
Tests to make sure that the most basic assembly works correctly with tagging.
12+
"""
13+
14+
# Create the basic assembly
15+
assy = generate_simple_nested_boxes()
16+
17+
# Create a mesh that has all the faces tagged as physical groups
18+
assy.assemblyToGmsh(mesh_path="tagged_mesh.msh")
319

420

521
def test_basic_cross_section():

0 commit comments

Comments
 (0)