Skip to content

Commit 7b4c94c

Browse files
committed
final cleanup, add example
1 parent 645c8a8 commit 7b4c94c

File tree

6 files changed

+91
-6
lines changed

6 files changed

+91
-6
lines changed
47.6 KB
Loading

doc/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def intersphinx_pyansys_geometry(switcher_version: str):
293293
"examples/03_modeling/design_tree": "_static/thumbnails/design_tree.png",
294294
"examples/03_modeling/service_colors": "_static/thumbnails/service_colors.png",
295295
"examples/03_modeling/surface_bodies": "_static/thumbnails/quarter_sphere.png",
296+
"examples/03_modeling/chamfer": "_static/thumbnails/chamfer.png",
296297
"examples/04_applied/01_naca_airfoils": "_static/thumbnails/naca_airfoils.png",
297298
"examples/04_applied/02_naca_fluent": "_static/thumbnails/naca_fluent.png",
298299
}

doc/source/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ These examples demonstrate service-based modeling operations.
4848
examples/03_modeling/design_tree.mystnb
4949
examples/03_modeling/service_colors.mystnb
5050
examples/03_modeling/surface_bodies.mystnb
51+
examples/03_modeling/chamfer.mystnb
5152

5253
Applied examples
5354
----------------
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .mystnb
5+
format_name: myst
6+
format_version: 0.13
7+
jupytext_version: 1.16.4
8+
kernelspec:
9+
display_name: Python 3 (ipykernel)
10+
language: python
11+
name: python3
12+
---
13+
14+
# Modeling: Chamfer edges and faces
15+
A chamfer is an angled cut on an edge. Chamfers can be created through the `Modeler.pull_tools` module.
16+
17+
+++
18+
19+
## Create a block
20+
Launch the modeler and create a block.
21+
22+
```{code-cell} ipython3
23+
from ansys.geometry.core import launch_modeler, Modeler
24+
25+
modeler = Modeler()
26+
print(modeler)
27+
```
28+
29+
```{code-cell} ipython3
30+
from ansys.geometry.core.sketch import Sketch
31+
from ansys.geometry.core.math import Point2D
32+
33+
design = modeler.create_design("chamfer_block")
34+
body = design.extrude_sketch("block", Sketch().box(Point2D([0, 0]), 1, 1), 1)
35+
36+
body.plot()
37+
```
38+
39+
## Chamfer edges
40+
Create a uniform chamfer on all edges of the block.
41+
42+
```{code-cell} ipython3
43+
modeler.pull_tools.chamfer(body.edges, distance=0.1)
44+
45+
body.plot()
46+
```
47+
48+
## Chamfer faces
49+
The chamfer of a face can also be modified. Create a chamfer on a single edge, then modify the chamfer distance value by providing the newly created face that represents the chamfer.
50+
51+
```{code-cell} ipython3
52+
body = design.extrude_sketch("box", Sketch().box(Point2D([0,0]), 1, 1), 1)
53+
54+
modeler.pull_tools.chamfer(body.edges[0], distance=0.1)
55+
56+
body.plot()
57+
```
58+
59+
```{code-cell} ipython3
60+
modeler.pull_tools.chamfer(body.faces[-1], distance=0.3)
61+
62+
body.plot()
63+
```

src/ansys/geometry/core/tools/pull_tools.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# SOFTWARE.
2222
"""Provides tools for pulling geometry."""
2323

24-
from typing import TYPE_CHECKING, Union
24+
from typing import TYPE_CHECKING, List, Union
2525

2626
from ansys.api.geometry.v0.commands_pb2 import ChamferRequest
2727
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
@@ -52,13 +52,15 @@ def __init__(self, grpc_client: GrpcClient):
5252

5353
@protect_grpc
5454
@min_backend_version(25, 1, 0)
55-
def chamfer(self, edge_or_face: Union["Edge", "Face"], distance: Real) -> bool:
55+
def chamfer(
56+
self, selection: Union["Edge", List["Edge"], "Face", List["Face"]], distance: Real
57+
) -> bool:
5658
"""Create a chamfer on an edge, or adjust the chamfer of a face.
5759
5860
Parameters
5961
----------
60-
edge_or_face : Edge | Face
61-
Edge or face to act on.
62+
edges_or_faces : Edge | List[Edge] | Face | List[Face]
63+
Edge(s) or face(s) to act on.
6264
distance : Real
6365
Chamfer distance.
6466
@@ -67,8 +69,13 @@ def chamfer(self, edge_or_face: Union["Edge", "Face"], distance: Real) -> bool:
6769
bool
6870
Success of chamfer command.
6971
"""
70-
edge_or_face.body._reset_tessellation_cache()
72+
selection = selection if isinstance(selection, list) else [selection]
7173

72-
result = self._commands_stub.Chamfer(ChamferRequest(id=edge_or_face.id, distance=distance))
74+
for ef in selection:
75+
ef.body._reset_tessellation_cache()
76+
77+
result = self._commands_stub.Chamfer(
78+
ChamferRequest(ids=[ef.id for ef in selection], distance=distance)
79+
)
7380

7481
return result.success

tests/integration/test_pull_tools.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,16 @@ def test_chamfer(modeler: Modeler):
4848
assert len(body.faces) == 7
4949
assert len(body.edges) == 15
5050
assert body.volume.m == pytest.approx(Quantity(0.875, UNITS.m**3).m, rel=1e-6, abs=1e-8)
51+
52+
# multiple edges
53+
body2 = design.extrude_sketch("box2", Sketch().box(Point2D([0, 0]), 1, 1), 1)
54+
assert len(body2.faces) == 6
55+
assert len(body2.edges) == 12
56+
assert body2.volume.m == pytest.approx(Quantity(1, UNITS.m**3).m, rel=1e-6, abs=1e-8)
57+
58+
modeler.pull_tools.chamfer(body2.edges, 0.1)
59+
assert len(body2.faces) == 26
60+
assert len(body2.edges) == 48
61+
assert body2.volume.m == pytest.approx(
62+
Quantity(0.945333333333333333, UNITS.m**3).m, rel=1e-6, abs=1e-8
63+
)

0 commit comments

Comments
 (0)