Skip to content

Commit dbc6c19

Browse files
beams fixes from comments on PR
1 parent 53e2d4e commit dbc6c19

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from ansys.geometry.core.errors import protect_grpc
2727

2828
from ..base.beams import GRPCBeamsService
29+
from .conversions import from_point3d_to_grpc_point
2930

3031

3132
class GRPCBeamsServiceV0(GRPCBeamsService):
@@ -50,37 +51,55 @@ def __init__(self, channel: grpc.Channel): # noqa: D102
5051
@protect_grpc
5152
def create_beam_segments(self, **kwargs) -> dict: # noqa: D102
5253
from ansys.api.geometry.v0.commands_pb2 import CreateBeamSegmentsRequest
54+
from ansys.api.geometry.v0.models_pb2 import Line
55+
56+
# Create the gRPC Line objects
57+
lines = []
58+
for segment in kwargs["segments"]:
59+
lines.append(
60+
Line(start=from_point3d_to_grpc_point(segment[0]),
61+
end=from_point3d_to_grpc_point(segment[1]))
62+
)
5363

5464
# Create the request - assumes all inputs are valid and of the proper type
5565
request = CreateBeamSegmentsRequest(
5666
profile=kwargs["profile_id"],
5767
parent=kwargs["parent_id"],
58-
lines=kwargs["lines"],
68+
lines=lines,
5969
)
6070

6171
# Call the gRPC service
6272
resp = self.stub.CreateBeamSegments(request)
6373

64-
# Return the response as a dictionary
74+
# Return the response - formatted as a dictionary
6575
return {
6676
"beam_ids": resp.ids,
6777
}
6878

6979
@protect_grpc
7080
def create_descriptive_beam_segments(self, **kwargs) -> dict: # noqa: D102
7181
from ansys.api.geometry.v0.commands_pb2 import CreateBeamSegmentsRequest
82+
from ansys.api.geometry.v0.models_pb2 import Line
83+
84+
# Create the gRPC Line objects
85+
lines = []
86+
for segment in kwargs["segments"]:
87+
lines.append(
88+
Line(start=from_point3d_to_grpc_point(segment[0]),
89+
end=from_point3d_to_grpc_point(segment[1]))
90+
)
7291

7392
# Create the request - assumes all inputs are valid and of the proper type
7493
request = CreateBeamSegmentsRequest(
7594
profile=kwargs["profile_id"],
7695
parent=kwargs["parent_id"],
77-
lines=kwargs["lines"],
96+
lines=lines,
7897
)
7998

8099
# Call the gRPC service
81100
resp = self.stub.CreateDescriptiveBeamSegments(request)
82101

83-
# Return the response as a dictionary
102+
# Return the response - formatted as a dictionary
84103
return {
85104
"created_beams": resp.created_beams,
86105
}
@@ -94,3 +113,6 @@ def delete_beam(self, **kwargs) -> dict: # noqa: D102
94113

95114
# Call the gRPC service
96115
_ = self.stub.DeleteBeam(request)
116+
117+
# Return the response - formatted as a dictionary
118+
return {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class GRPCBeamsServiceV1(GRPCBeamsService):
3232
"""Beams service for gRPC communication with the Geometry server.
3333
3434
This class provides methods to interact with the Geometry server's
35-
beams service. It is specifically designed for the v0 version of the
35+
beams service. It is specifically designed for the v1 version of the
3636
Geometry API.
3737
3838
Parameters

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,15 +1212,9 @@ def __create_beams_legacy(
12121212
-----
12131213
This is a legacy method, which is used in versions up to Ansys 25.1.1 products.
12141214
"""
1215-
lines = []
1216-
for segment in segments:
1217-
lines.append(
1218-
Line(start=point3d_to_grpc_point(segment[0]), end=point3d_to_grpc_point(segment[1]))
1219-
)
1220-
12211215
self._grpc_client.log.debug(f"Creating beams on {self.id}...")
12221216
response = self._grpc_client.services.beams.create_beam_segments(
1223-
parent_id=self.id, profile_id=profile.id, lines=lines
1217+
parent_id=self.id, profile_id=profile.id, segments=segments
12241218
)
12251219
self._grpc_client.log.debug("Beams successfully created.")
12261220

@@ -1257,19 +1251,12 @@ def __create_beams(
12571251
list[Beam]
12581252
A list of the created Beams.
12591253
"""
1260-
lines = []
1261-
for segment in segments:
1262-
lines.append(
1263-
Line(start=point3d_to_grpc_point(segment[0]), end=point3d_to_grpc_point(segment[1]))
1264-
)
1265-
12661254
self._grpc_client.log.debug(f"Creating beams on {self.id}...")
12671255
response = self._grpc_client.services.beams.create_descriptive_beam_segments(
1268-
parent_id=self.id, profile_id=profile.id, lines=lines
1256+
parent_id=self.id, profile_id=profile.id, segments=segments
12691257
)
12701258
self._grpc_client.log.debug("Beams successfully created.")
12711259

1272-
print(response)
12731260
beams = []
12741261
for beam in response.get("created_beams", []):
12751262
cross_section = BeamCrossSectionInfo(

0 commit comments

Comments
 (0)