Skip to content

Commit 709cb51

Browse files
wip
1 parent 389417a commit 709cb51

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,8 @@ def split_body(self, **kwargs) -> dict:
228228
def create_body_from_loft_profiles_with_guides(self, **kwargs) -> dict:
229229
"""Create a body from loft profiles with guides."""
230230
pass
231+
232+
@abstractmethod
233+
def stitch(self, **kwargs) -> dict:
234+
"""Stitch bodies."""
235+
pass

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,3 +825,26 @@ def create_body_from_loft_profiles_with_guides(self, **kwargs) -> dict: # noqa:
825825
"master_id": new_body.master_id,
826826
"is_surface": new_body.is_surface,
827827
}
828+
829+
@protect_grpc
830+
def stitch(self, **kwargs) -> dict: # noqa: D102
831+
from ansys.api.geometry.v0.bodies_pb2 import StitchRequest, StitchRequestData
832+
833+
# Create the request - assumes all inputs are valid and of the proper type
834+
request = StitchRequest(
835+
StitchRequestData(
836+
ids=kwargs["body_ids"],
837+
tolerance=from_measurement_to_server_length(kwargs["tolerance"]),
838+
)
839+
)
840+
841+
# Call the gRPC service
842+
resp = self.stub.Stitch(request=request)
843+
844+
# Return the response - formatted as a dictionary
845+
return {
846+
"id": resp.id,
847+
"name": resp.name,
848+
"master_id": resp.master_id,
849+
"is_surface": resp.is_surface,
850+
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,3 +1833,39 @@ def revolve_edges(
18331833

18341834
design = get_design_from_edge(edges[0])
18351835
design._update_design_inplace()
1836+
1837+
@min_backend_version(26, 1, 0)
1838+
def stitch_bodies(self, bodies: list["Body"], tolerance: Distance | Quantity | Real) -> bool:
1839+
"""Stitch bodies together.
1840+
1841+
Parameters
1842+
----------
1843+
bodies : list[Body]
1844+
Bodies to stitch.
1845+
tolerance : Distance | Quantity | Real
1846+
Tolerance to use when stitching bodies. Default units are meters.
1847+
1848+
Returns
1849+
-------
1850+
bool
1851+
``True`` when successful, ``False`` when failed.
1852+
"""
1853+
from ansys.geometry.core.designer.body import Body
1854+
1855+
check_type_all_elements_in_iterable(bodies, Body)
1856+
1857+
for body in bodies:
1858+
body._reset_tessellation_cache()
1859+
1860+
tolerance = tolerance if isinstance(tolerance, Distance) else Distance(tolerance)
1861+
1862+
result = self._grpc_client._services.bodies.stitch(
1863+
body_ids=[body.id for body in bodies],
1864+
tolerance=tolerance,
1865+
)
1866+
1867+
if result.get("success"):
1868+
design = get_design_from_body(bodies[0])
1869+
design._update_design_inplace()
1870+
1871+
return result.get("success")

0 commit comments

Comments
 (0)