2424import grpc
2525
2626from ansys .geometry .core .errors import protect_grpc
27+ from ansys .geometry .core .misc .measurements import DEFAULT_UNITS
2728
2829from ..base .beams import GRPCBeamsService
30+ from ..base .conversions import to_distance
31+ from .conversions import (
32+ build_grpc_id ,
33+ from_grpc_angle_to_angle ,
34+ from_grpc_curve_to_curve ,
35+ from_grpc_frame_to_frame ,
36+ from_grpc_material_to_material ,
37+ from_grpc_point_to_point3d ,
38+ from_grpc_quantity_to_distance ,
39+ from_grpc_quantity_to_float ,
40+ from_plane_to_grpc_plane ,
41+ from_point3d_to_grpc_point ,
42+ )
2943
3044
3145class GRPCBeamsServiceV1 (GRPCBeamsService ):
@@ -43,26 +57,203 @@ class GRPCBeamsServiceV1(GRPCBeamsService):
4357
4458 @protect_grpc
4559 def __init__ (self , channel : grpc .Channel ): # noqa: D102
46- from ansys .api .discovery .v1 .assignments .beams import BeamsStub
60+ from ansys .api .discovery .v1 .design .extensions .beam_pb2_grpc import (
61+ BeamStub ,
62+ )
63+ from ansys .api .discovery .v1 .engineeringdata .beamprofiledata_pb2_grpc import (
64+ BeamProfileDataStub ,
65+ )
4766
48- self .stub = BeamsStub (channel )
67+ self .beam_profile_commands_stub = BeamProfileDataStub (channel )
68+ self .beam_commands_stub = BeamStub (channel )
4969
5070 @protect_grpc
5171 def create_beam_segments (self , ** kwargs ) -> dict : # noqa: D102
52- raise NotImplementedError
72+ from ansys .api .discovery .v1 .commonmessages_pb2 import Line
73+ from ansys .api .discovery .v1 .engineeringdata .beamprofiledata_pb2 import (
74+ CreateBeamProfileSegmentsRequest ,
75+ CreateBeamProfileSegmentsRequestData ,
76+ )
77+
78+ # Create the gRPC Line objects
79+ lines = []
80+ for segment in kwargs ["segments" ]:
81+ lines .append (
82+ Line (
83+ start = from_point3d_to_grpc_point (segment [0 ]),
84+ end = from_point3d_to_grpc_point (segment [1 ]),
85+ )
86+ )
87+
88+ # Create the request - assumes all inputs are valid and of the proper type
89+ request = CreateBeamProfileSegmentsRequest (
90+ request_data = [
91+ CreateBeamProfileSegmentsRequestData (
92+ profile_id = build_grpc_id (kwargs ["profile_id" ]),
93+ parent_id = build_grpc_id (kwargs ["parent_id" ]),
94+ lines = lines ,
95+ )
96+ ]
97+ )
98+
99+ # Call the gRPC service
100+ response = self .beam_profile_commands_stub .CreateSegments (request )
101+
102+ # Return the response - formatted as a dictionary
103+ return {
104+ "beam_ids" : [
105+ [beam .id for beam in response_data .beams_ids ]
106+ for response_data in response .response_data
107+ ]
108+ }
53109
54110 @protect_grpc
55111 def create_descriptive_beam_segments (self , ** kwargs ) -> dict : # noqa: D102
56- raise NotImplementedError
112+ from ansys .api .discovery .v1 .commonmessages_pb2 import Line
113+ from ansys .api .discovery .v1 .engineeringdata .beamprofiledata_pb2 import (
114+ CreateBeamProfileSegmentsRequest ,
115+ CreateBeamProfileSegmentsRequestData ,
116+ )
117+
118+ from ansys .geometry .core .shapes .parameterization import Interval , ParamUV
119+
120+ # Create the gRPC Line objects
121+ lines = []
122+ for segment in kwargs ["segments" ]:
123+ lines .append (
124+ Line (
125+ start = from_point3d_to_grpc_point (segment [0 ]),
126+ end = from_point3d_to_grpc_point (segment [1 ]),
127+ )
128+ )
129+
130+ # Create the request - assumes all inputs are valid and of the proper type
131+ request = CreateBeamProfileSegmentsRequest (
132+ request_data = [
133+ CreateBeamProfileSegmentsRequestData (
134+ profile_id = build_grpc_id (kwargs ["profile_id" ]),
135+ parent_id = build_grpc_id (kwargs ["parent_id" ]),
136+ lines = lines ,
137+ )
138+ ]
139+ )
140+
141+ # Call the gRPC service
142+ response = self .beam_profile_commands_stub .CreateDescriptiveSegments (request )
143+
144+ # Return the response - formatted as a dictionary
145+ return {
146+ "created_beams" : [
147+ {
148+ "cross_section" : {
149+ "section_anchor" : beam .cross_section .section_anchor ,
150+ "section_angle" : (
151+ from_grpc_angle_to_angle (beam .cross_section .section_angle )
152+ ).m_as (DEFAULT_UNITS .SERVER_ANGLE ),
153+ "section_frame" : from_grpc_frame_to_frame (beam .cross_section .section_frame ),
154+ "section_profile" : [
155+ [
156+ {
157+ "geometry" : from_grpc_curve_to_curve (curve .curve ),
158+ "start" : from_grpc_point_to_point3d (curve .start ),
159+ "end" : from_grpc_point_to_point3d (curve .end ),
160+ "interval" : Interval (curve .interval_start , curve .interval_end ),
161+ "length" : to_distance (curve .length ).value ,
162+ }
163+ for curve in curve_list .curves
164+ ]
165+ for curve_list in beam .cross_section .section_profile
166+ ],
167+ },
168+ "properties" : {
169+ "area" : from_grpc_quantity_to_float (beam .properties .area ),
170+ "centroid" : ParamUV (beam .properties .centroid_x , beam .properties .centroid_y ),
171+ "warping_constant" : from_grpc_quantity_to_float (
172+ beam .properties .warping_constant
173+ ),
174+ "ixx" : from_grpc_quantity_to_float (beam .properties .ixx ),
175+ "ixy" : from_grpc_quantity_to_float (beam .properties .ixy ),
176+ "iyy" : from_grpc_quantity_to_float (beam .properties .iyy ),
177+ "shear_center" : ParamUV (
178+ beam .properties .shear_center_x , beam .properties .shear_center_y
179+ ),
180+ "torsional_constant" : from_grpc_quantity_to_float (
181+ beam .properties .torsional_constant
182+ ),
183+ },
184+ "id" : beam .id .id ,
185+ "start" : from_grpc_point_to_point3d (beam .shape .start ),
186+ "end" : from_grpc_point_to_point3d (beam .shape .end ),
187+ "name" : beam .name ,
188+ "is_deleted" : beam .is_deleted ,
189+ "is_reversed" : beam .is_reversed ,
190+ "is_rigid" : beam .is_rigid ,
191+ "material" : from_grpc_material_to_material (beam .material ),
192+ "shape" : {
193+ "geometry" : from_grpc_curve_to_curve (beam .shape .curve ),
194+ "start" : from_grpc_point_to_point3d (beam .shape .start ),
195+ "end" : from_grpc_point_to_point3d (beam .shape .end ),
196+ "interval" : Interval (beam .shape .interval_start , beam .shape .interval_end ),
197+ "length" : from_grpc_quantity_to_distance (beam .shape .length ),
198+ },
199+ "beam_type" : beam .type ,
200+ }
201+ for response_data in response .response_data
202+ for beam in response_data .beams
203+ ],
204+ }
57205
58206 @protect_grpc
59207 def delete_beam (self , ** kwargs ) -> dict : # noqa: D102
60- raise NotImplementedError
208+ from ansys .api .discovery .v1 .commonmessages_pb2 import MultipleEntitiesRequest
209+
210+ # Create the request - assumes all inputs are valid and of the proper type
211+ request = MultipleEntitiesRequest (ids = [build_grpc_id (kwargs ["beam_id" ])])
212+
213+ # Call the gRPC service
214+ _ = self .beam_commands_stub .Delete (request )
215+
216+ # Return the response - formatted as a dictionary
217+ return {}
61218
62219 @protect_grpc
63220 def delete_beam_profile (self , ** kwargs ) -> dict : # noqa: D102
64- raise NotImplementedError
221+ from ansys .api .discovery .v1 .commonmessages_pb2 import MultipleEntitiesRequest
222+
223+ # Create the request - assumes all inputs are valid and of the proper type
224+ request = MultipleEntitiesRequest (ids = [build_grpc_id (kwargs ["id" ])])
225+
226+ # Call the gRPC service
227+ _ = self .beam_profile_commands_stub .Delete (request )
228+
229+ # Return the response - formatted as a dictionary
230+ return {}
65231
66232 @protect_grpc
67233 def create_beam_circular_profile (self , ** kwargs ) -> dict : # noqa: D102
68- raise NotImplementedError
234+ from ansys .api .discovery .v1 .engineeringdata .beamprofiledata_pb2 import (
235+ CreateBeamProfileCircularRequest ,
236+ CreateBeamProfileCircularRequestData ,
237+ )
238+
239+ from .conversions import from_length_to_grpc_quantity
240+
241+ # Create the request - assumes all inputs are valid and of the proper type
242+ request = CreateBeamProfileCircularRequest (
243+ request_data = [
244+ CreateBeamProfileCircularRequestData (
245+ origin = from_point3d_to_grpc_point (kwargs ["center" ]),
246+ radius = from_length_to_grpc_quantity (kwargs ["radius" ]),
247+ plane = from_plane_to_grpc_plane (kwargs ["plane" ]),
248+ name = kwargs ["name" ],
249+ )
250+ ]
251+ )
252+
253+ # Call the gRPC service
254+ response = self .beam_profile_commands_stub .CreateCircular (request )
255+
256+ # Return the response - formatted as a dictionary
257+ # Note: response.ids is a repeated field, we return the first one
258+ created_beam_entity = response .ids [0 ]
259+ return {"id" : created_beam_entity .id }
0 commit comments