Skip to content

Commit 65f43c4

Browse files
jacobrkerstetterpyansys-ci-botpre-commit-ci[bot]RobPasMue
authored
feat: replace face (#1664)
Co-authored-by: jkerstet <[email protected]> Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 034e060 commit 65f43c4

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

doc/changelog.d/1664.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
replace face

src/ansys/geometry/core/designer/geometry_commands.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
ModifyLinearPatternRequest,
4040
PatternRequest,
4141
RenameObjectRequest,
42+
ReplaceFaceRequest,
4243
)
4344
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
4445
from ansys.geometry.core.connection import GrpcClient
@@ -842,3 +843,42 @@ def update_fill_pattern(
842843
)
843844

844845
return result.result.success
846+
847+
@protect_grpc
848+
@min_backend_version(25, 2, 0)
849+
def replace_face(
850+
self,
851+
target_selection: Union["Face", list["Face"]],
852+
replacement_selection: Union["Face", list["Face"]],
853+
) -> bool:
854+
"""Replace a face with another face.
855+
856+
Parameters
857+
----------
858+
target_selection : Union[Face, list[Face]]
859+
The face or faces to replace.
860+
replacement_selection : Union[Face, list[Face]]
861+
The face or faces to replace with.
862+
863+
Returns
864+
-------
865+
bool
866+
``True`` when successful, ``False`` when failed.
867+
"""
868+
target_selection: list["Face"] = (
869+
target_selection if isinstance(target_selection, list) else [target_selection]
870+
)
871+
replacement_selection: list["Face"] = (
872+
replacement_selection
873+
if isinstance(replacement_selection, list)
874+
else [replacement_selection]
875+
)
876+
877+
result = self._commands_stub.ReplaceFace(
878+
ReplaceFaceRequest(
879+
target_selection=[selection._grpc_id for selection in target_selection],
880+
replacement_selection=[selection._grpc_id for selection in replacement_selection],
881+
)
882+
)
883+
884+
return result.success

tests/integration/test_geometry_commands.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,28 @@ def test_fill_pattern(modeler: Modeler):
547547
assert success
548548
assert base.volume.m == pytest.approx(Quantity(1.60730091830, UNITS.m**3).m, rel=1e-6, abs=1e-8)
549549
assert len(base.faces) == 56
550+
551+
552+
def test_replace_face(modeler: Modeler):
553+
"""Test replacing a face with another face."""
554+
design = modeler.create_design("replace_face")
555+
base = design.extrude_sketch("box", Sketch().box(Point2D([0, 0]), 1, 1), 1)
556+
cutout = design.extrude_sketch("cylinder", Sketch().circle(Point2D([-0.4, -0.4]), 0.05), 1)
557+
base.subtract(cutout)
558+
559+
# replace face with a new face
560+
new_face = design.extrude_sketch("new_face", Sketch().box(Point2D([0, 0]), 0.1, 0.1), 1)
561+
success = modeler.geometry_commands.replace_face(base.faces[-1], new_face.faces[0])
562+
assert success
563+
assert base.volume.m == pytest.approx(
564+
Quantity(0.992146018366, UNITS.m**3).m, rel=1e-6, abs=1e-8
565+
)
566+
assert len(base.faces) == 7
567+
568+
# replace face with an existing face
569+
success = modeler.geometry_commands.replace_face(base.faces[-1], base.faces[0])
570+
assert success
571+
assert base.volume.m == pytest.approx(
572+
Quantity(0.992146018366, UNITS.m**3).m, rel=1e-6, abs=1e-8
573+
)
574+
assert len(base.faces) == 7

0 commit comments

Comments
 (0)