Skip to content

Commit c7ec5d8

Browse files
jacobrkerstetterRobPasMuepyansys-ci-botumutsoysalansyspre-commit-ci[bot]
authored
feat: component name setting (#1820)
Co-authored-by: Roberto Pastor Muela <[email protected]> Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Umut Soysal <[email protected]> Co-authored-by: Jacob Kerstetter <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ce21ad6 commit c7ec5d8

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

doc/changelog.d/1820.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
component name setting

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
]
2525

2626
dependencies = [
27-
"ansys-api-geometry==0.4.46",
27+
"ansys-api-geometry==0.4.47",
2828
"ansys-tools-path>=0.3,<1",
2929
"attrs!=24.3.0",
3030
"beartype>=0.11.0,<0.20",

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
SetSharedTopologyRequest,
5353
)
5454
from ansys.api.geometry.v0.components_pb2_grpc import ComponentsStub
55-
from ansys.api.geometry.v0.models_pb2 import Direction, Line, TrimmedCurveList
55+
from ansys.api.geometry.v0.models_pb2 import Direction, Line, SetObjectNameRequest, TrimmedCurveList
5656
from ansys.geometry.core.connection.client import GrpcClient
5757
from ansys.geometry.core.connection.conversions import (
5858
grpc_matrix_to_matrix,
@@ -266,6 +266,20 @@ def name(self) -> str:
266266
"""Name of the component."""
267267
return self._name
268268

269+
@name.setter
270+
def name(self, value: str) -> None:
271+
"""Set the name of the component."""
272+
self.set_name(value)
273+
274+
@protect_grpc
275+
@check_input_types
276+
@min_backend_version(25, 2, 0)
277+
def set_name(self, name: str) -> None:
278+
"""Set the name of the component."""
279+
self._grpc_client.log.debug(f"Renaming component {self.id} from '{self.name}' to '{name}'.")
280+
self._component_stub.SetName(SetObjectNameRequest(id=self._grpc_id, name=name))
281+
self._name = name
282+
269283
@property
270284
def instance_name(self) -> str:
271285
"""Name of the component instance."""

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ def end(self) -> Point3D:
214214
# Only for versions earlier than 24.2.0 (before the introduction of the shape property)
215215
self._grpc_client.log.debug("Requesting edge end point from server.")
216216
response = self._edges_stub.GetStartAndEndPoints(self._grpc_id)
217-
return Point3D([response.end.x, response.end.y, response.end.z])
217+
return Point3D(
218+
[response.end.x, response.end.y, response.end.z], unit=DEFAULT_UNITS.SERVER_LENGTH
219+
)
218220

219221
@property
220222
@protect_grpc

tests/integration/test_design.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,17 @@ def test_set_face_color(modeler: Modeler):
31923192
faces[3].opacity = 255
31933193

31943194

3195+
def test_set_component_name(modeler: Modeler):
3196+
"""Test the setting of component names."""
3197+
3198+
design = modeler.create_design("ComponentNameTest")
3199+
component = design.add_component("Component1")
3200+
assert component.name == "Component1"
3201+
3202+
component.name = "ChangedComponentName"
3203+
assert component.name == "ChangedComponentName"
3204+
3205+
31953206
def test_get_face_bounding_box(modeler: Modeler):
31963207
"""Test getting the bounding box of a face."""
31973208
design = modeler.create_design("face_bounding_box")

0 commit comments

Comments
 (0)