Skip to content

Commit 6f9dbee

Browse files
tested and working
1 parent 585f721 commit 6f9dbee

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -771,27 +771,28 @@ def create_body_from_loft_profiles_with_guides(self, **kwargs): # noqa: D102
771771

772772
# Create request object - assumes all inputs are valid and of the proper type
773773
request = CreateBodyFromLoftWithGuidesRequest(
774-
request_data=CreateBodyFromLoftWithGuidesRequestData(
774+
request_data=[CreateBodyFromLoftWithGuidesRequestData(
775775
name=kwargs["name"],
776776
parent=EntityIdentifier(id=kwargs["parent_id"]),
777777
profiles=[TrimmedCurveList(
778778
curves=[from_trimmed_curve_to_grpc_trimmed_curve(tc) for tc in profile]
779779
) for profile in kwargs["profiles"]],
780-
guide_ids=TrimmedCurveList(
780+
guides=TrimmedCurveList(
781781
curves=[from_trimmed_curve_to_grpc_trimmed_curve(tc) for tc in kwargs["guides"]]
782782
),
783-
)
783+
)]
784784
)
785785

786786
# Call the gRPC service
787787
response = self.stub.CreateBodyFromLoftWithGuides(request)
788788

789789
# Return the response - formatted as a dictionary
790-
return {
791-
[{
790+
return [
791+
{
792792
"id": body.id,
793793
"name": body.name,
794794
"master_id": body.master_id,
795795
"is_surface": body.is_surface,
796-
}] for body in response.created_bodies
797-
}
796+
}
797+
for body in response.created_bodies
798+
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ def create_body_from_loft_profiles_with_guides(
997997
guides=guides,
998998
)
999999

1000-
return self.__build_body_from_response(response)
1000+
return self.__build_body_from_response(response[0])
10011001

10021002
@check_input_types
10031003
@ensure_design_is_active

tests/integration/test_design.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,52 @@ def test_create_body_from_loft_profile(modeler: Modeler):
29152915
assert result.volume.m == 0
29162916

29172917

2918+
def test_create_body_from_loft_profile_with_guides(modeler: Modeler):
2919+
"""Test the ``create_body_from_loft_profile_with_guides()`` method to create a vase
2920+
shape.
2921+
"""
2922+
design_sketch = modeler.create_design("LoftProfileWithGuides")
2923+
2924+
circle1 = Circle(origin=[0, 0, 0], radius=8)
2925+
circle2 = Circle(origin=[0, 0, 10], radius=10)
2926+
2927+
profile1 = circle1.trim(Interval(0, 2 * np.pi))
2928+
profile2 = circle2.trim(Interval(0, 2 * np.pi))
2929+
2930+
def circle_point(center, radius, angle_deg):
2931+
# Returns a point on the circle at the given angle
2932+
angle_rad = np.deg2rad(angle_deg)
2933+
return Point3D([
2934+
center[0] + radius.m * np.cos(angle_rad),
2935+
center[1] + radius.m * np.sin(angle_rad),
2936+
center[2]]
2937+
)
2938+
2939+
angles = [0, 90, 180, 270]
2940+
guide_curves = []
2941+
2942+
for angle in angles:
2943+
pt1 = circle_point(circle1.origin, circle1.radius, angle)
2944+
pt2 = circle_point(circle2.origin, circle2.radius, angle)
2945+
2946+
# Create a guide curve (e.g., a line or spline) between pt1 and pt2
2947+
guide_curve = NURBSCurve.fit_curve_from_points([pt1, pt2], 1).trim(Interval(0, 1))
2948+
guide_curves.append(guide_curve)
2949+
2950+
# Call the method
2951+
result = design_sketch.create_body_from_loft_profiles_with_guides(
2952+
"vase", [[profile1], [profile2]], guide_curves
2953+
)
2954+
2955+
# Assert that the resulting body has only one face.
2956+
assert len(result.faces) == 1
2957+
2958+
# check volume of body
2959+
# expected is 0 since it's not a closed surface
2960+
assert result.volume.m == 0
2961+
assert result.is_surface is True
2962+
2963+
29182964
def test_revolve_sketch(modeler: Modeler):
29192965
"""Test revolving a circular profile for a quarter donut."""
29202966
# Initialize the donut sketch design

0 commit comments

Comments
 (0)