|
67 | 67 | point3d_to_grpc_point, |
68 | 68 | sketch_shapes_to_grpc_geometries, |
69 | 69 | tess_to_pd, |
| 70 | + trimmed_curve_to_grpc_trimmed_curve, |
70 | 71 | unit_vector_to_grpc_direction, |
71 | 72 | ) |
72 | 73 | from ansys.geometry.core.designer.edge import CurveType, Edge |
|
93 | 94 | min_backend_version, |
94 | 95 | ) |
95 | 96 | from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle, Distance |
| 97 | +from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve |
96 | 98 | from ansys.geometry.core.sketch.sketch import Sketch |
97 | 99 | from ansys.geometry.core.typing import Real |
98 | 100 |
|
@@ -1574,30 +1576,60 @@ def add_midsurface_offset( # noqa: D102 |
1574 | 1576 | @protect_grpc |
1575 | 1577 | @ensure_design_is_active |
1576 | 1578 | def imprint_curves( # noqa: D102 |
1577 | | - self, faces: list[Face], sketch: Sketch |
| 1579 | + self, faces: list[Face], sketch: Sketch = None, trimmed_curves: list[TrimmedCurve] = None |
1578 | 1580 | ) -> tuple[list[Edge], list[Face]]: |
| 1581 | + """Imprint curves onto the specified faces using a sketch or edges. |
| 1582 | +
|
| 1583 | + Parameters |
| 1584 | + ---------- |
| 1585 | + faces : list[Face] |
| 1586 | + The list of faces to imprint the curves onto. |
| 1587 | + sketch : Sketch, optional |
| 1588 | + The sketch containing curves to imprint. |
| 1589 | + trimmed_curves : list[TrimmedCurve], optional |
| 1590 | + The list of curves to be imprinted. If sketch is provided, this parameter is ignored. |
| 1591 | +
|
| 1592 | + Returns |
| 1593 | + ------- |
| 1594 | + tuple[list[Edge], list[Face]] |
| 1595 | + A tuple containing the list of new edges and faces created by the imprint operation. |
| 1596 | + """ |
| 1597 | + if sketch is None and self._template._grpc_client.backend_version < (25, 2, 0): |
| 1598 | + raise ValueError( |
| 1599 | + "A sketch must be provided for imprinting when using API versions below 25.2.0." |
| 1600 | + ) |
| 1601 | + |
| 1602 | + if sketch is None and trimmed_curves is None: |
| 1603 | + raise ValueError("Either a sketch or edges must be provided for imprinting.") |
| 1604 | + |
1579 | 1605 | # Verify that each of the faces provided are part of this body |
1580 | 1606 | body_faces = self.faces |
1581 | 1607 | for provided_face in faces: |
1582 | | - is_found = False |
1583 | | - for body_face in body_faces: |
1584 | | - if provided_face.id == body_face.id: |
1585 | | - is_found = True |
1586 | | - break |
1587 | | - if not is_found: |
| 1608 | + if not any(provided_face.id == body_face.id for body_face in body_faces): |
1588 | 1609 | raise ValueError(f"Face with ID {provided_face.id} is not part of this body.") |
1589 | 1610 |
|
1590 | 1611 | self._template._grpc_client.log.debug( |
1591 | | - f"Imprinting curves provided on {self.id} " |
1592 | | - + f"for faces {[face.id for face in faces]}." |
| 1612 | + f"Imprinting curves on {self.id} for faces {[face.id for face in faces]}." |
1593 | 1613 | ) |
1594 | 1614 |
|
| 1615 | + curves = None |
| 1616 | + grpc_trimmed_curves = None |
| 1617 | + |
| 1618 | + if sketch: |
| 1619 | + curves = sketch_shapes_to_grpc_geometries(sketch._plane, sketch.edges, sketch.faces) |
| 1620 | + |
| 1621 | + if trimmed_curves: |
| 1622 | + grpc_trimmed_curves = [ |
| 1623 | + trimmed_curve_to_grpc_trimmed_curve(curve) for curve in trimmed_curves |
| 1624 | + ] |
| 1625 | + |
1595 | 1626 | imprint_response = self._template._commands_stub.ImprintCurves( |
1596 | 1627 | ImprintCurvesRequest( |
1597 | 1628 | body=self._id, |
1598 | | - curves=sketch_shapes_to_grpc_geometries(sketch._plane, sketch.edges, sketch.faces), |
| 1629 | + curves=curves, |
1599 | 1630 | faces=[face._id for face in faces], |
1600 | | - plane=plane_to_grpc_plane(sketch.plane), |
| 1631 | + plane=plane_to_grpc_plane(sketch.plane) if sketch else None, |
| 1632 | + trimmed_curves=grpc_trimmed_curves, |
1601 | 1633 | ) |
1602 | 1634 | ) |
1603 | 1635 |
|
|
0 commit comments