From e001916622029e9a002c236014e47a2a0e28710e Mon Sep 17 00:00:00 2001 From: Dominik Gresch Date: Thu, 10 Jul 2025 15:46:36 +0200 Subject: [PATCH] Allow stackup thickness and area weight to be None When the fabrics in a stackup do have a material, or the stackup has no fabrics, the 'thickness' and 'area_weight' properties cannot be computed. This change allows these properties to be 'None' in these cases. This case is only supported in the 26.1 server version or later. Earlier versions would raise an error when getting the properties under these conditions. --- src/ansys/acp/core/_tree_objects/stackup.py | 8 ++++++-- tests/unittests/test_stackup.py | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ansys/acp/core/_tree_objects/stackup.py b/src/ansys/acp/core/_tree_objects/stackup.py index 54fe69b6d6..3b68c62670 100644 --- a/src/ansys/acp/core/_tree_objects/stackup.py +++ b/src/ansys/acp/core/_tree_objects/stackup.py @@ -222,8 +222,12 @@ def _create_stub(self) -> stackup_pb2_grpc.ObjectServiceStub: locked: ReadOnlyProperty[bool] = grpc_data_property_read_only("properties.locked") status = grpc_data_property_read_only("properties.status", from_protobuf=status_type_from_pb) - thickness: ReadOnlyProperty[float] = grpc_data_property_read_only("properties.thickness") - area_weight: ReadOnlyProperty[float] = grpc_data_property_read_only("properties.area_weight") + thickness: ReadOnlyProperty[float] = grpc_data_property_read_only( + "properties.thickness", check_optional=True + ) + area_weight: ReadOnlyProperty[float] = grpc_data_property_read_only( + "properties.area_weight", check_optional=True + ) symmetry = grpc_data_property( "properties.symmetry", diff --git a/tests/unittests/test_stackup.py b/tests/unittests/test_stackup.py index 0bbbae7ab0..8e8123aadc 100644 --- a/tests/unittests/test_stackup.py +++ b/tests/unittests/test_stackup.py @@ -190,9 +190,22 @@ def test_add_fabric(parent_object): assert stackup.fabrics[-1].angle == 45.0 -def test_fabric_wit_angle(parent_object): +def test_fabric_with_angle(parent_object): fabric1 = parent_object.create_fabric() fabric_with_angle = FabricWithAngle(fabric=fabric1, angle=45.0) assert fabric_with_angle != FabricWithAngle(fabric=parent_object.create_fabric(), angle=45.0) assert fabric_with_angle != FabricWithAngle(fabric=fabric1, angle=55.0) assert fabric_with_angle == FabricWithAngle(fabric=fabric1, angle=45.0) + + +def test_fabric_without_material(parent_object, skip_before_version): + """Verify that a fabric without material can be added to a stackup. + + Checks that the properties which should not be computable are 'None'. + """ + skip_before_version("26.1") + fabric = parent_object.create_fabric() + stackup = parent_object.create_stackup() + stackup.add_fabric(fabric) + assert stackup.thickness is None + assert stackup.area_weight is None