Skip to content

Commit 72f4fa1

Browse files
offset_faces tested and working
1 parent c2f2d71 commit 72f4fa1

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

src/ansys/geometry/core/_grpc/_services/base/faces.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,8 @@ def draft_faces(self, **kwargs) -> dict:
148148
def get_round_info(self, **kwargs) -> dict:
149149
"""Get round information for a selection of faces."""
150150
pass
151+
152+
@abstractmethod
153+
def offset_faces(self, **kwargs) -> dict:
154+
"""Offset a selection of faces."""
155+
pass

src/ansys/geometry/core/_grpc/_services/v0/faces.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,28 @@ def get_round_info(self, **kwargs): # noqa: D102
520520
"along_u": response.along_u,
521521
"radius": response.radius,
522522
}
523+
524+
@protect_grpc
525+
def offset_faces(self, **kwargs) -> dict: # noqa: D102
526+
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
527+
from ansys.api.geometry.v0.faces_pb2 import OffsetFacesRequest, OffsetFacesRequestData
528+
529+
# Create the request - assumes all inputs are valid and of the proper type
530+
request = OffsetFacesRequest(
531+
request_data=[OffsetFacesRequestData(
532+
faces=[EntityIdentifier(id=face_id) for face_id in kwargs["face_ids"]],
533+
offset=from_measurement_to_server_length(kwargs["distance"]),
534+
direction=from_unit_vector_to_grpc_direction(kwargs["direction"]),
535+
extrude_type=kwargs["extrude_type"].value,
536+
)]
537+
)
538+
539+
# Call the gRPC service
540+
response = self.stub.OffsetFaces(request=request)
541+
542+
# Return the response - formatted as a dictionary
543+
return {
544+
"results": [
545+
[face.id for face in response_data.new_faces]
546+
for response_data in response.response_data]
547+
}

src/ansys/geometry/core/_grpc/_services/v1/faces.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,7 @@ def draft_faces(self, **kwargs) -> dict: # noqa: D102
134134
@protect_grpc
135135
def get_round_info(self, **kwargs): # noqa: D102
136136
raise NotImplementedError
137+
138+
@protect_grpc
139+
def offset_faces(self, **kwargs): # noqa: D102
140+
raise NotImplementedError

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,3 +1763,33 @@ def thicken_faces(
17631763

17641764
# Return success flag
17651765
return result.get("success")
1766+
1767+
@min_backend_version(26, 1, 0)
1768+
def offset_faces(
1769+
self,
1770+
faces: list["Face"],
1771+
distance: Distance | Quantity | Real,
1772+
direction: UnitVector3D,
1773+
extrude_type: ExtrudeType,
1774+
) -> None:
1775+
"""Offset the specified faces by the specified distance in the specified direction.
1776+
1777+
Parameters
1778+
----------
1779+
faces : list[Face]
1780+
The faces to offset.
1781+
distance : Distance | Quantity | Real
1782+
The distance to offset the faces.
1783+
direction : UnitVector3D
1784+
The direction to offset the faces.
1785+
extrude_type : ExtrudeType
1786+
The type of extrusion to use.
1787+
"""
1788+
distance = distance if isinstance(distance, Distance) else Distance(distance)
1789+
1790+
_ = self._grpc_client._services.faces.offset_faces(
1791+
face_ids=[face.id for face in faces],
1792+
distance=distance,
1793+
direction=direction,
1794+
extrude_type=extrude_type,
1795+
)

tests/integration/test_geometry_commands.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,3 +1405,30 @@ def test_thicken_surface_body(modeler: Modeler):
14051405
assert design.bodies[0].volume.m == pytest.approx(
14061406
Quantity(0.4, UNITS.m**3).m, rel=1e-6, abs=1e-8
14071407
)
1408+
1409+
def test_offset_faces(modeler: Modeler):
1410+
"""Test offsetting faces."""
1411+
design = modeler.create_design("offset_faces")
1412+
box = design.extrude_sketch("box", Sketch().box(Point2D([0, 0]), 2, 2), 2)
1413+
1414+
assert len(box.faces) == 6
1415+
assert box.volume.m == pytest.approx(Quantity(8, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1416+
1417+
# Offset the top face
1418+
modeler.geometry_commands.offset_faces([box.faces[1]], 0.1, UNITVECTOR3D_Z, ExtrudeType.ADD)
1419+
1420+
assert box.volume.m == pytest.approx(Quantity(8.4, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1421+
1422+
# Test with two boxes
1423+
box2 = design.extrude_sketch("box2", Sketch().box(Point2D([3, 0]), 2, 2), 2)
1424+
1425+
assert len(box2.faces) == 6
1426+
assert box2.volume.m == pytest.approx(Quantity(8, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1427+
1428+
# Offset the top face of both boxes
1429+
modeler.geometry_commands.offset_faces(
1430+
[box.faces[1], box2.faces[1]], 0.1, UNITVECTOR3D_Z, ExtrudeType.ADD
1431+
)
1432+
1433+
assert box.volume.m == pytest.approx(Quantity(8.8, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1434+
assert box2.volume.m == pytest.approx(Quantity(8.4, UNITS.m**3).m, rel=1e-6, abs=1e-8)

0 commit comments

Comments
 (0)